[Python-Dev] datetime's strftime implementation: by design or bug

Eric V. Smith eric+python-dev at trueblade.com
Mon Sep 11 20:31:45 CEST 2006

[I hope this belongs on python-dev, since it's about the design of 
something.  But if not, let me know and I'll post to c.l.py.]

I'm willing to file a bug report and patch on this, but I'd like to know 
if it's by design or not.

In datetimemodule.c, the function wrap_strftime() insists that the 
length of a format string be <= 127 chars, by forcing the length into a 
char.  This seems like a bug to me.  wrap_strftime() calls time's 
strftime(), which doesn't have this limitation because it uses size_t.

 >>> import datetime
 >>> datetime.datetime.now().strftime('x'*128)
Traceback (most recent call last):
   File "<stdin>", line 1, in ?

 >>> import datetime
 >>> datetime.datetime.now().strftime('x'*256)
in wrap_strftime
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
SystemError: Objects/stringobject.c:4077: bad argument to internal function

 >>> import time
 >>> time.strftime('x'*128)

But before I write this up, I'd like to know if anyone knows if this is 
by design or not.

This is reproducible on Windows 2.4.3, and Linux 2.3.3 and 2.5c1.



More information about the Python-Dev mailing list