summaryrefslogtreecommitdiffstats
path: root/Modules/timemodule.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-12-16 11:28:32 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-12-16 11:28:32 (GMT)
commitc345ce1a69b3c4a46d87ef56d859bc70abfc74b4 (patch)
tree5481a8c3e31ae8a423aed9199a1fe2b22694d1c0 /Modules/timemodule.c
parent87448819abd4900bcb36857c6706d8562c97a099 (diff)
downloadcpython-c345ce1a69b3c4a46d87ef56d859bc70abfc74b4.zip
cpython-c345ce1a69b3c4a46d87ef56d859bc70abfc74b4.tar.gz
cpython-c345ce1a69b3c4a46d87ef56d859bc70abfc74b4.tar.bz2
Issue #10350: Read and save errno before calling a function which might overwrite it.
Original patch by Hallvard B Furuseth.
Diffstat (limited to 'Modules/timemodule.c')
-rw-r--r--Modules/timemodule.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index 33751fa..17d9c38 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -527,12 +527,14 @@ time_strftime(PyObject *self, PyObject *args)
* will be ahead of time...
*/
for (i = 1024; ; i += i) {
+ int err;
outbuf = (time_char *)PyMem_Malloc(i*sizeof(time_char));
if (outbuf == NULL) {
PyErr_NoMemory();
break;
}
buflen = format_time(outbuf, i, fmt, &buf);
+ err = errno;
if (buflen > 0 || i >= 256 * fmtlen) {
/* If the buffer is 256 times as long as the format,
it's probably not failing for lack of room!
@@ -550,7 +552,7 @@ time_strftime(PyObject *self, PyObject *args)
PyMem_Free(outbuf);
#if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__)
/* VisualStudio .NET 2005 does this properly */
- if (buflen == 0 && errno == EINVAL) {
+ if (buflen == 0 && err == EINVAL) {
PyErr_SetString(PyExc_ValueError, "Invalid format string");
break;
}