Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
size must be positive
  • Loading branch information
vstinner committed Jun 24, 2024
commit aefcbf898adee901bf3990310a039c6618237f8c
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