Skip to content

Commit d3b0056

Browse files
committed
Restore backwards compatibility
1 parent ca016d7 commit d3b0056

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Modules/timemodule.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -813,9 +813,7 @@ time_strftime1(time_char **outbuf, size_t *bufsize,
813813
/* I hate these functions that presume you know how big the output
814814
* will be ahead of time...
815815
*/
816-
int attempts = 0;
817816
while (1) {
818-
attempts ++;
819817
if (*bufsize > PY_SSIZE_T_MAX/sizeof(time_char)) {
820818
PyErr_NoMemory();
821819
return NULL;
@@ -851,13 +849,15 @@ time_strftime1(time_char **outbuf, size_t *bufsize,
851849
return NULL;
852850
}
853851
if (*bufsize >= 256 * fmtlen) {
854-
/* If the buffer is 256 times as long as the format, it's probably not
855-
failing for lack of room! More likely, `format_time` doesn't like the
856-
format string. For instance we end up here with musl if the format
857-
string ends with a '%'.
852+
/* If the buffer is 256 times as long as the format, it's probably
853+
not failing for lack of room! More likely, `format_time` doesn't
854+
like the format string. For instance we end up here with musl if
855+
the format string ends with a '%'.
856+
857+
Ideally we should raise ValueError("Invalid format string")
858+
here. For backwards compatibility, return empty string instead.
858859
*/
859-
PyErr_Format(PyExc_ValueError, "Invalid format string attempts: %d *outbuf: '%.8s'", attempts, *outbuf);
860-
return NULL;
860+
return PyUnicode_FromStringAndSize(NULL, 0);
861861
}
862862
*bufsize += *bufsize;
863863
}

0 commit comments

Comments
 (0)