Mercurial > hg > octave-nkf
changeset 13975:16158606112d
avoid memory error in strptime
* oct-time.cc (octave_strptime::init): Allocate extra space for first
argument to C-library strptime function.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 02 Dec 2011 04:02:58 -0500 |
parents | f5bd61eb032f |
children | fb5955171b0b |
files | liboctave/oct-time.cc |
diffstat | 1 files changed, 14 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/oct-time.cc +++ b/liboctave/oct-time.cc @@ -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)