Commit e7cd921d authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Fix undetected overflow in calendar routines.

* Fault only happens if labs(year) > INT_MAX/dpy!
parent 512329c2
#include <limits.h>
#include <stdio.h>
#include "cdi.h" /* CALENDAR_ */
#include "error.h"
#include "timebase.h"
......@@ -112,17 +114,17 @@ static int encode_day(int dpy, int year, int month, int day)
{
int i;
int *dpm = NULL;
double rval;
rval = dpy * year + day;
long rval = (long)dpy * year + day;
if ( dpy == 360 ) dpm = month_360;
else if ( dpy == 365 ) dpm = month_365;
else if ( dpy == 366 ) dpm = month_366;
if ( dpm ) for ( i = 0; i < month-1; i++ ) rval += dpm[i];
if (rval > INT_MAX || rval < INT_MIN)
Error("Unhandled date: %ld", rval);
return (rval);
return (int)rval;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment