Mailing List Archive

strptime: unpleasant surprise (py 1.5.2 on Linux)
Hi, Folks--

I'm working on some date-related functions, and wanted to see what
kind of exception 'strptime' would raise if I fed it a European-style
date string with a US format. But instead of an exception, I get:

>>> import time
>>> time.strptime('31/7/99', '%x') # US locale, wants D/M/Y
Segmentation fault (core import)

>>> dumped DateTime # mxDateTime version
>>> DateTime.strptime('31/7/99', '%x')
Segmentation fault (core dumped)

Surely this isn't what we want, is it? Has anyone else noticed this
behavior?

I'm running Python 1.5.2 on RedHat Linux 5.1 (2.0.34 kernel with glibc
2.0.7).

Matt Gushee
Portland, Maine, USA
mgushee@havenrock.com
strptime: unpleasant surprise (py 1.5.2 on Linux) [ In reply to ]
It shouldn't segfault, however, the function does work if
you reverse the arguments:

Python 1.5.2 (#8, May 28 1999, 21:09:50) [GCC 2.7.2.3] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import time
>>> time.strptime('%x', '31/7/99')
Traceback (innermost last):
File "<stdin>", line 1, in ?
ValueError: format mismatch
>>>

I'm not sure, their may be patches to fix the strptime
segfault on linux problem - check www.python.org.

scott


On Sun, Jul 25, 1999 at 09:16:55AM +0900, Matt Gushee wrote:
| Hi, Folks--
|
| I'm working on some date-related functions, and wanted to see what
| kind of exception 'strptime' would raise if I fed it a European-style
| date string with a US format. But instead of an exception, I get:
|
| >>> import time
| >>> time.strptime('31/7/99', '%x') # US locale, wants D/M/Y
| Segmentation fault (core import)
|
| >>> dumped DateTime # mxDateTime version
| >>> DateTime.strptime('31/7/99', '%x')
| Segmentation fault (core dumped)
|
| Surely this isn't what we want, is it? Has anyone else noticed this
| behavior?
|
| I'm running Python 1.5.2 on RedHat Linux 5.1 (2.0.34 kernel with glibc
| 2.0.7).
|
| Matt Gushee
| Portland, Maine, USA
| mgushee@havenrock.com
|
|
| --
| http://www.python.org/mailman/listinfo/python-list
strptime: unpleasant surprise (py 1.5.2 on Linux) [ In reply to ]
On 25 Jul 1999 09:16:55 +0900, Matt Gushee
<mgushee@havenrock.com> wrote:
>Hi, Folks--
>
>I'm working on some date-related functions, and wanted to see what
>kind of exception 'strptime' would raise if I fed it a European-style
>date string with a US format. But instead of an exception, I get:

This may be a Linux libc bug. It's not clear what the behaviour is (should
be) on invalid dates from the manpage. It's probably hard or impossible
for python to check the format of the date before passing it to the OS's
strptime, since %x uses the locale's format and any argument is potentially
valid for %x in some locale.

Your best bet might be to bug the glibc folks with a bug report, since the
analagous C program also segfaults:

#include <time.h>

main() {
struct tm tm;
strptime("31/7/99", "%x", &tm);
}

(gdb) run
Starting program: /usr/local/home/jepler/a.out

Program received signal SIGSEGV, Segmentation fault.
0x40056eba in __strncasecmp (s1=0x4009ebef "Sunday", s2=0x0, n=6)
at ../sysdeps/generic/strncase.c:41
../sysdeps/generic/strncase.c:41: No such file or directory.
(gdb) where
#0 0x40056eba in __strncasecmp (s1=0x4009ebef "Sunday", s2=0x0, n=6)
at ../sysdeps/generic/strncase.c:41
#1 0x4006c3d3 in strptime_internal (buf=0x0,
format=0x4009eb20 "%a %b %e %H:%M:%S %Y", tm=0xbffff62c,
decided=0xbffff614) at strptime.c:261
#2 0x4006c890 in strptime_internal (buf=0x804854f "31/7/99",
format=0x804854c "%x", tm=0xbffff62c, decided=0xbffff614) at strptime.c:368
#3 0x4006de30 in strptime (buf=0x804854f "31/7/99", format=0x804854c "%x",
tm=0xbffff62c) at strptime.c:736
#4 0x80484f1 in main () at tst.c:5

Jeff
--
\/ http://www.freshmeat.net/ Jeff Epler jepler@inetnebr.com
You may easily play a joke on a man who likes to argue -- agree with him.
-- Ed Howe