diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-03-21 17:15:42 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-03-21 17:15:42 (GMT) |
commit | 6ced7c433353208e5b9d4dc25018937f1c9ae87d (patch) | |
tree | 61efdd2c527ab2eeeff1dd306218b91efbe1b91d /Modules/_datetimemodule.c | |
parent | 44afe2b35a3f82f26d35a2cec507ec6d59e6d6d3 (diff) | |
download | cpython-6ced7c433353208e5b9d4dc25018937f1c9ae87d.zip cpython-6ced7c433353208e5b9d4dc25018937f1c9ae87d.tar.gz cpython-6ced7c433353208e5b9d4dc25018937f1c9ae87d.tar.bz2 |
Issue #10833: Use PyErr_Format() and PyUnicode_FromFormat() instead of
PyOS_snprintf() to avoid temporary buffer allocated on the stack and a
conversion from bytes to Unicode.
Diffstat (limited to 'Modules/_datetimemodule.c')
-rw-r--r-- | Modules/_datetimemodule.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index cd44471..f50cae0 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -766,7 +766,7 @@ typedef struct PyObject *name; } PyDateTime_TimeZone; -/* The interned UTC timezone instance */ +/* The interned UTC timezone instance */ static PyObject *PyDateTime_TimeZone_UTC; /* Create new timezone instance checking offset range. This @@ -3287,7 +3287,6 @@ timezone_repr(PyDateTime_TimeZone *self) static PyObject * timezone_str(PyDateTime_TimeZone *self) { - char buf[10]; int hours, minutes, seconds; PyObject *offset; char sign; @@ -3313,11 +3312,9 @@ timezone_str(PyDateTime_TimeZone *self) Py_DECREF(offset); minutes = divmod(seconds, 60, &seconds); hours = divmod(minutes, 60, &minutes); - assert(seconds == 0); /* XXX ignore sub-minute data, curently not allowed. */ - PyOS_snprintf(buf, sizeof(buf), "UTC%c%02d:%02d", sign, hours, minutes); - - return PyUnicode_FromString(buf); + assert(seconds == 0); + return PyUnicode_FromFormat("UTC%c%02d:%02d", sign, hours, minutes); } static PyObject * |