diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-03-21 13:26:24 +0100 |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-03-21 13:26:24 +0100 |
commit | 758975ac24d240747b3e4f3bc7fa682cc94d6ebc (patch) | |
tree | 351fb59aee97ee1977bc3c6e110f2ac9b95f6023 /Modules/timemodule.c | |
parent | 1339099e7b7d43ecfee6af2fc213b08547222fa9 (diff) | |
download | cpython-758975ac24d240747b3e4f3bc7fa682cc94d6ebc.tar.gz |
Issue #10833: Use PyUnicode_FromFormat() and PyErr_Format() instead of
PyOS_snprintf().
Diffstat (limited to 'Modules/timemodule.c')
-rw-r--r-- | Modules/timemodule.c | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/Modules/timemodule.c b/Modules/timemodule.c index c3b51efc5b..b24cc35909 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -601,31 +601,20 @@ _asctime(struct tm *timeptr) { /* Inspired by Open Group reference implementation available at * http://pubs.opengroup.org/onlinepubs/009695399/functions/asctime.html */ - static char wday_name[7][3] = { + static char wday_name[7][4] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; - static char mon_name[12][3] = { + static char mon_name[12][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; - char buf[20]; /* 'Sun Sep 16 01:03:52\0' */ - int n; - - n = PyOS_snprintf(buf, sizeof(buf), "%.3s %.3s%3d %.2d:%.2d:%.2d", - wday_name[timeptr->tm_wday], - mon_name[timeptr->tm_mon], - timeptr->tm_mday, timeptr->tm_hour, - timeptr->tm_min, timeptr->tm_sec); - /* XXX: since the fields used by snprintf above are validated in checktm, - * the following condition should never trigger. We keep the check because - * historically fixed size buffer used in asctime was the source of - * crashes. */ - if (n + 1 != sizeof(buf)) { - PyErr_SetString(PyExc_ValueError, "unconvertible time"); - return NULL; - } - - return PyUnicode_FromFormat("%s %d", buf, 1900 + timeptr->tm_year); + return PyUnicode_FromFormat( + "%s %s%3d %.2d:%.2d:%.2d %d", + wday_name[timeptr->tm_wday], + mon_name[timeptr->tm_mon], + timeptr->tm_mday, timeptr->tm_hour, + timeptr->tm_min, timeptr->tm_sec, + 1900 + timeptr->tm_year); } static PyObject * |