Mercurial > hg > octave-lyh
comparison liboctave/oct-time.cc @ 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 | 6cdfbe90e2ab |
comparison
equal
deleted
inserted
replaced
13974:f5bd61eb032f | 13975:16158606112d |
---|---|
34 #include "strftime.h" | 34 #include "strftime.h" |
35 | 35 |
36 #include "lo-error.h" | 36 #include "lo-error.h" |
37 #include "lo-math.h" | 37 #include "lo-math.h" |
38 #include "lo-utils.h" | 38 #include "lo-utils.h" |
39 #include "oct-locbuf.h" | |
39 #include "oct-time.h" | 40 #include "oct-time.h" |
40 | 41 |
41 octave_time::octave_time (const octave_base_tm& tm) | 42 octave_time::octave_time (const octave_base_tm& tm) |
42 : ot_unix_time (), ot_usec () | 43 : ot_unix_time (), ot_usec () |
43 { | 44 { |
264 #if defined (HAVE_STRUCT_TM_TM_ZONE) | 265 #if defined (HAVE_STRUCT_TM_TM_ZONE) |
265 char *ps = strsave (""); | 266 char *ps = strsave (""); |
266 t.tm_zone = ps; | 267 t.tm_zone = ps; |
267 #endif | 268 #endif |
268 | 269 |
269 char *p = strsave (str.c_str ()); | 270 // FIXME -- the following kluge avoids a memory access problem with |
271 // strptime in some versions of GNU libc. | |
272 // http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=650714 | |
273 | |
274 const char *pstr = str.c_str (); | |
275 size_t len = str.length (); | |
276 const int extra = 128; | |
277 OCTAVE_LOCAL_BUFFER (char, p, len + extra); | |
278 char *pp = p; | |
279 for (size_t i = 0; i < len; i++) | |
280 *pp++ = *pstr++; | |
281 for (size_t i = len; i < extra; i++) | |
282 *pp++ = 0; | |
270 | 283 |
271 char *q = gnulib::strptime (p, fmt.c_str (), &t); | 284 char *q = gnulib::strptime (p, fmt.c_str (), &t); |
272 | 285 |
273 // Fill in wday and yday, but only if mday is valid and the mon and year | 286 // Fill in wday and yday, but only if mday is valid and the mon and year |
274 // are filled in, avoiding issues with mktime and invalid dates. | 287 // are filled in, avoiding issues with mktime and invalid dates. |
287 if (q) | 300 if (q) |
288 nchars = q - p + 1; | 301 nchars = q - p + 1; |
289 else | 302 else |
290 nchars = 0; | 303 nchars = 0; |
291 | 304 |
292 delete [] p; | |
293 | |
294 octave_base_tm::init (&t); | 305 octave_base_tm::init (&t); |
295 | 306 |
296 #if defined (HAVE_STRUCT_TM_TM_ZONE) | 307 #if defined (HAVE_STRUCT_TM_TM_ZONE) |
297 delete [] ps; | 308 delete [] ps; |
298 #endif | 309 #endif |