struct tm *tmp;
time_t pt;
-void gm_check (time_t t)
+void gm_check (time_t t, int min_year, int max_year)
{
tmp = gmtime (&t);
- if (tmp == NULL || tmp->tm_year < -1900)
+ if ( tmp == NULL ||
+ /* Check tm_year overflow */
+ tmp->tm_year < min_year || tmp->tm_year > max_year)
tmp = NULL;
else
pt = t;
tmp = NULL;
pt = 0;
#ifdef MAXLONG
- gm_check (MAXLONG);
+ gm_check (MAXLONG, 69, 0x7fffffff);
#endif
if (tmp == NULL || tmp->tm_year < 0) {
for (i = 63; i >= 0; i--) {
time_t x = pt | ((time_t)1 << i);
- if (x < 0) continue;
- gm_check (x);
+ if (x < 0 || x < pt) continue;
+ gm_check (x, 69, 0x7fffffff);
}
}
printf ("sGMTIME_max=%ld\n", pt);
tmp = NULL;
pt = 0;
#ifdef MINLONG
- gm_check (MINLONG);
+ gm_check (MINLONG, -1900, 70);
#endif
if (tmp == NULL) {
for (i = 36; i >= 0; i--) {
time_t x = pt - ((time_t)1 << i);
if (x > 0) continue;
- gm_check (x);
+ gm_check (x, -1900, 70);
}
}
printf ("sGMTIME_min=%ld\n", pt);
struct tm *tmp;
time_t pt;
-void local_check (time_t t)
+void local_check (time_t t, int min_year, int max_year)
{
if (sizeof (time_t) > 4 && t > 0x7ffffffffffff000LL)
tmp = NULL;
else
tmp = localtime (&t);
- if (tmp == NULL || tmp->tm_year < -1900)
+ if ( tmp == NULL ||
+ /* Check tm_year overflow */
+ tmp->tm_year < min_year || tmp->tm_year > max_year)
tmp = NULL;
else
pt = t;
tmp = NULL;
pt = 0;
#ifdef MAXLONG
- local_check (MAXLONG);
+ local_check (MAXLONG, 69, 0x7fffffff);
#endif
if (tmp == NULL || tmp->tm_year < 0) {
for (i = 63; i >= 0; i--) {
time_t x = pt | ((time_t)1 << i);
- if (x < 0) continue;
- local_check (x);
+ if (x < 0 || x < pt) continue;
+ local_check (x, 69, 0x7fffffff);
}
}
printf ("sLOCALTIME_max=%ld\n", pt);
tmp = NULL;
pt = 0;
#ifdef MINLONG
- local_check (MINLONG);
+ local_check (MINLONG, -1900, 70);
#endif
if (tmp == NULL) {
for (i = 36; i >= 0; i--) {
time_t x = pt - ((time_t)1 << i);
if (x > 0) continue;
- local_check (x);
+ local_check (x, -1900, 70);
}
}
printf ("sLOCALTIME_min=%ld\n", pt);