summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>2009-02-16 09:13:20 (GMT)
committerHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>2009-02-16 09:13:20 (GMT)
commit575d13306583791160e902d59d43d825c0d49c3b (patch)
tree9fc39b4913872222390d3abd11158d2b7cf80ade /Modules
parentdebb98d91f6358e85c7790386ab9b6f52299da98 (diff)
downloadcpython-575d13306583791160e902d59d43d825c0d49c3b.zip
cpython-575d13306583791160e902d59d43d825c0d49c3b.tar.gz
cpython-575d13306583791160e902d59d43d825c0d49c3b.tar.bz2
Issue #5249: time.strftime returned malformed string when format string
contained non ascii character on windows.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/timemodule.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index c32b53d..7e18086 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -508,9 +508,11 @@ time_strftime(PyObject *self, PyObject *args)
return NULL;
}
- /* Convert the unicode string to an ascii one */
- fmt = _PyUnicode_AsString(format);
-
+ /* Convert the unicode string to an ascii one */
+ format = PyUnicode_AsEncodedString(format, TZNAME_ENCODING, NULL);
+ if (format == NULL)
+ return NULL;
+ fmt = PyBytes_AS_STRING(format);
fmtlen = strlen(fmt);
/* I hate these functions that presume you know how big the output
@@ -519,6 +521,7 @@ time_strftime(PyObject *self, PyObject *args)
for (i = 1024; ; i += i) {
outbuf = (char *)PyMem_Malloc(i);
if (outbuf == NULL) {
+ Py_DECREF(format);
return PyErr_NoMemory();
}
buflen = strftime(outbuf, i, fmt, &buf);
@@ -532,6 +535,7 @@ time_strftime(PyObject *self, PyObject *args)
ret = PyUnicode_Decode(outbuf, buflen,
TZNAME_ENCODING, NULL);
PyMem_Free(outbuf);
+ Py_DECREF(format);
return ret;
}
PyMem_Free(outbuf);
@@ -539,6 +543,7 @@ time_strftime(PyObject *self, PyObject *args)
/* VisualStudio .NET 2005 does this properly */
if (buflen == 0 && errno == EINVAL) {
PyErr_SetString(PyExc_ValueError, "Invalid format string");
+ Py_DECREF(format);
return 0;
}
#endif