Skip to content

Commit a78bfe1

Browse files
committed
Issue a more meaningful error if strftime keeps returning a NULL pointer.
Run the loop up to and including 8k.
1 parent 0d85be1 commit a78bfe1

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

Modules/timemodule.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ time_strftime(self, args)
242242
/* I hate these functions that presume you know how big the output
243243
* will be ahead of time...
244244
*/
245-
for (i = 1024 ; i < 8192 ; i += 1024) {
245+
for (i = 1024 ; i <= 8192 ; i += 1024) {
246246
outbuf = malloc(i);
247247
if (outbuf == NULL) {
248248
return PyErr_NoMemory();
@@ -255,7 +255,9 @@ time_strftime(self, args)
255255
}
256256
free(outbuf);
257257
}
258-
return PyErr_NoMemory();
258+
PyErr_SetString(PyExc_ValueError,
259+
"bad strftime format or result too big");
260+
return NULL;
259261
}
260262
#endif /* HAVE_STRFTIME */
261263

@@ -443,6 +445,7 @@ floatsleep(double secs)
443445
double secs;
444446
#endif /* MPW */
445447
{
448+
/* XXX Should test for MS_WIN32 first! */
446449
#ifdef HAVE_SELECT
447450
struct timeval t;
448451
double frac;

0 commit comments

Comments
 (0)