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]. 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.cmod,v 1.158 2005/05/01 12:13:07 per Exp $ + || $Id: builtin.cmod,v 1.159 2008/04/22 18:18:17 mast Exp $   */      #include "global.h"
548:    *! @seealso    *! @[time()], @[localtime()], @[mktime()], @[gmtime()]    */ - PIKEFUN string ctime(int timestamp) + PIKEFUN string ctime(int|object timestamp)    efun;    optflags OPT_TRY_OPTIMIZE;   { -  time_t i=(time_t)timestamp; -  char *s = ctime (&i); +  LONGEST tt; +  time_t i; +  char *s; +  +  if (timestamp->type != PIKE_T_INT + #ifdef AUTO_BIGNUM +  && !is_bignum_object_in_svalue (timestamp) + #endif +  ) SIMPLE_ARG_TYPE_ERROR ("ctime", 1, "int"); + #ifdef AUTO_BIGNUM +  if (timestamp->type == PIKE_T_INT) +  tt = Pike_sp[0-1].u.integer; +  else + #if SIZEOF_LONGEST > SIZEOF_INT_TYPE +  if (!int64_from_bignum (&tt, Pike_sp[0-1].u.object)) + #endif +  SIMPLE_ARG_ERROR ("ctime", 1, "Integer too large."); + #else +  tt = Pike_sp[0-1].u.integer; + #endif +  + #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 +  i = (time_t) tt; +  +  s = ctime (&i);    if (!s) Pike_error ("ctime() on this system cannot handle "    "the timestamp %ld.\n", (long) i);    RETURN make_shared_string(s);