]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merged revisions 69664 via svnmerge from
authorHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
Mon, 16 Feb 2009 09:29:31 +0000 (09:29 +0000)
committerHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
Mon, 16 Feb 2009 09:29:31 +0000 (09:29 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r69664 | hirokazu.yamamoto | 2009-02-16 18:13:20 +0900 | 2 lines

  Issue #5249: time.strftime returned malformed string when format string
  contained non ascii character on windows.
........

Misc/NEWS
Modules/timemodule.c

index 10fa18788cf0d5834ecf9d2dc59ab755d9e2ba22..46cac5bb96a48eab40e915cf0fe08797913d7869 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 3.0.2?
 Core and Builtins
 -----------------
 
+- Issue #5249: time.strftime returned malformed string when format string
+  contained non ascii character on windows.
+
 Library
 -------
 
index c32b53d4633b240ff85c15a67b8549df3fad7be7..7e180862bb59aa55bcef0f43e1f1ec26d691c90b 100644 (file)
@@ -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