strptime: unpleasant surprise (py 1.5.2 on Linux)

Jeff Epler jepler at inetnebr.com
Tue Jul 27 11:10:13 EDT 1999


On 25 Jul 1999 09:16:55 +0900, Matt Gushee
 <mgushee at 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 at inetnebr.com
You may easily play a joke on a man who likes to argue -- agree with him.
		-- Ed Howe




More information about the Python-list mailing list