mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
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.
This commit is contained in:
parent
44afe2b35a
commit
6ced7c4333
6 changed files with 36 additions and 65 deletions
|
|
@ -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 *
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue