# HG changeset patch # User John W. Eaton # Date 1322816578 18000 # Node ID 16158606112d6e5c5427bf429378bf726d6116e5 # Parent f5bd61eb032f94059361c48f06bb0253fa1eea6a avoid memory error in strptime * oct-time.cc (octave_strptime::init): Allocate extra space for first argument to C-library strptime function. diff -r f5bd61eb032f -r 16158606112d liboctave/oct-time.cc --- a/liboctave/oct-time.cc Fri Dec 02 03:51:38 2011 -0500 +++ b/liboctave/oct-time.cc Fri Dec 02 04:02:58 2011 -0500 @@ -36,6 +36,7 @@ #include "lo-error.h" #include "lo-math.h" #include "lo-utils.h" +#include "oct-locbuf.h" #include "oct-time.h" octave_time::octave_time (const octave_base_tm& tm) @@ -266,7 +267,19 @@ t.tm_zone = ps; #endif - char *p = strsave (str.c_str ()); + // FIXME -- the following kluge avoids a memory access problem with + // strptime in some versions of GNU libc. + // http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=650714 + + const char *pstr = str.c_str (); + size_t len = str.length (); + const int extra = 128; + OCTAVE_LOCAL_BUFFER (char, p, len + extra); + char *pp = p; + for (size_t i = 0; i < len; i++) + *pp++ = *pstr++; + for (size_t i = len; i < extra; i++) + *pp++ = 0; char *q = gnulib::strptime (p, fmt.c_str (), &t); @@ -289,8 +302,6 @@ else nchars = 0; - delete [] p; - octave_base_tm::init (&t); #if defined (HAVE_STRUCT_TM_TM_ZONE)