Branch: Tag:

2008-04-22

2008-04-22 18:18:17 by Martin Stjernholm <mast@lysator.liu.se>

Fixed overflow error in mktime when sizeof(time_t) > sizeof(INT_TYPE). This
fixes [bug 4525 (#4525)]. Fixed gmtime, localtime and ctime to handle bignums in the
same circumstances.

Rev: src/builtin.cmod:1.159
Rev: src/builtin_functions.c:1.562
Rev: src/pike_int_types.h:1.4

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.561 2007/06/10 18:39:02 mast Exp $ + || $Id: builtin_functions.c,v 1.562 2008/04/22 18:18:17 mast Exp $   */      #include "global.h" - RCSID("$Id: builtin_functions.c,v 1.561 2007/06/10 18:39:02 mast Exp $"); + RCSID("$Id: builtin_functions.c,v 1.562 2008/04/22 18:18:17 mast Exp $");   #include "interpret.h"   #include "svalue.h"   #include "pike_macros.h"
4557: Inside #if defined(HAVE_GMTIME)
  PMOD_EXPORT void f_gmtime(INT32 args)   {    struct tm *tm; -  INT_TYPE tt; +  LONGEST tt;    time_t t;    -  get_all_args("gmtime", args, "%i", &tt); +  get_all_args("gmtime", args, "%l", &tt);    -  t = tt; + #if SIZEOF_TIME_T < SIZEOF_LONGEST +  if (tt > MAX_TIME_T || tt < MIN_TIME_T) +  SIMPLE_ARG_ERROR ("gmtime", 1, "Timestamp outside valid range."); + #endif +  t = (time_t) tt; +     tm = gmtime(&t);    if (!tm) Pike_error ("gmtime() on this system cannot handle "    "the timestamp %ld.\n", (long) t);
4619: Inside #if defined(HAVE_LOCALTIME)
  PMOD_EXPORT void f_localtime(INT32 args)   {    struct tm *tm; -  INT_TYPE tt; +  LONGEST tt;    time_t t;    -  get_all_args("localtime", args, "%i", &tt); +  get_all_args("localtime", args, "%l", &tt);    -  t = tt; + #if SIZEOF_TIME_T < SIZEOF_LONGEST +  if (tt > MAX_TIME_T || tt < MIN_TIME_T) +  SIMPLE_ARG_ERROR ("gmtime", 1, "Timestamp outside valid range."); + #endif +  t = (time_t) tt; +     tm = localtime(&t);    if (!tm) Pike_error ("localtime() on this system cannot handle "    "the timestamp %ld.\n", (long) t);
5040:    }       pop_n_elems(args); + #if SIZEOF_TIME_T > SIZEOF_INT_TYPE +  push_int64 (retval); + #else    push_int(retval); -  + #endif   }   #define GOT_F_MKTIME   #endif /* HAVE_MKTIME || HAVE_LOCALTIME */