Skip to content

Commit

Permalink
size must be positive
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Jun 24, 2024
1 parent 4635f5f commit aefcbf8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
3 changes: 1 addition & 2 deletions Doc/c-api/unicode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1567,8 +1567,7 @@ object.
Writer the UCS4 string *str* into *writer*.
*size* is a number of UCS4 characters. If *size* is equal to ``-1``, get the
string length (search the NUL character).
*size* is a number of UCS4 characters.
On success, return ``0``.
On error, set an exception, leave the writer unchanged, and return ``-1``.
Expand Down
5 changes: 3 additions & 2 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2298,8 +2298,9 @@ PyUnicodeWriter_WriteUCS4(PyUnicodeWriter *pub_writer,
_PyUnicodeWriter *writer = (_PyUnicodeWriter*)pub_writer;

if (size < 0) {
size = 0;
for (; str[size] != '\0'; size++);
PyErr_SetString(PyExc_TypeError,
"size must be positive");
return NULL;
}

if (size == 0) {
Expand Down

0 comments on commit aefcbf8

Please sign in to comment.