Branch: Tag:

2004-12-22

2004-12-22 12:50:09 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Fix for localtime() returning NULL in mktime().
Fixes [bug 3855 (#3855)].

Rev: src/builtin_functions.c:1.474

2:   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: builtin_functions.c,v 1.473 2004/12/14 16:22:00 mast Exp $ + || $Id: builtin_functions.c,v 1.474 2004/12/22 12:50:09 grubba Exp $   */      #include "global.h" - RCSID("$Id: builtin_functions.c,v 1.473 2004/12/14 16:22:00 mast Exp $"); + RCSID("$Id: builtin_functions.c,v 1.474 2004/12/22 12:50:09 grubba Exp $");   #include "interpret.h"   #include "svalue.h"   #include "pike_macros.h"
4161: Inside #if defined (HAVE_GMTIME) || defined (HAVE_LOCALTIME)
   */   static time_t my_tm_diff(const struct tm *t1, const struct tm *t2)   { -  time_t base = (t1->tm_year - t2->tm_year) * 32140800; +  time_t base;    -  +  /* Win32 localtime() returns NULL for all dates before Jan 01, 1970. */ +  if (!t2) return -1; +  +  base = (t1->tm_year - t2->tm_year) * 32140800; +     /* Overflow detection. (Should possibly be done on the other fields    * too to cope with very large invalid dates.) */    if ((t1->tm_year > t2->tm_year) && (base < 0))
4205: Inside #if defined (HAVE_GMTIME) || defined (HAVE_LOCALTIME)
   fprintf (stderr, "diff: %d\n", diff_ts);   #endif    +  if (!current_tm) { + #ifdef DEBUG_MY_TIME_INVERSE +  fprintf (stderr, "outside range for timefn().\n"); + #endif +  return 0; +  } +     if (!diff_ts) {    /* Got a satisfactory time, but if target_tm has an opinion on    * DST we should check if we can return an alternative in the