summaryrefslogtreecommitdiffstats
path: root/Modules/datetimemodule.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-06-27 08:14:17 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-06-27 08:14:17 (GMT)
commitf69d9f6818225fc2613230c5dc11c181085db383 (patch)
tree41adffd0bafe34bcfa52f4f8f09b088fc7c3e38f /Modules/datetimemodule.c
parentdf9eff061e67ead5af3433c34b5f58451bc201a0 (diff)
downloadcpython-f69d9f6818225fc2613230c5dc11c181085db383.zip
cpython-f69d9f6818225fc2613230c5dc11c181085db383.tar.gz
cpython-f69d9f6818225fc2613230c5dc11c181085db383.tar.bz2
SF bug #761337: datetime.strftime fails on trivial format string
The interning of short strings violates the refcnt==1 assumption for _PyString_Resize(). A simple fix is to boost the initial value of "totalnew" by 1. Combined with an NULL argument to PyString_FromStringAndSize(), this assures that resulting format string is not interned. This will remain true even if the implementation of PyString_FromStringAndSize() changes because only the uninitialized strings that can be interned are those of zero length. Added a test case.
Diffstat (limited to 'Modules/datetimemodule.c')
-rw-r--r--Modules/datetimemodule.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c
index 164492e..d8aed17 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -1175,7 +1175,7 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
* a new format. Since computing the replacements for those codes
* is expensive, don't unless they're actually used.
*/
- totalnew = PyString_Size(format); /* realistic if no %z/%Z */
+ totalnew = PyString_Size(format) + 1; /* realistic if no %z/%Z */
newfmt = PyString_FromStringAndSize(NULL, totalnew);
if (newfmt == NULL) goto Done;
pnew = PyString_AsString(newfmt);