Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 09819ef

Browse files
bpo-32827: Fix usage of _PyUnicodeWriter_Prepare() in decoding errors handler. (GH-5636) (GH-5650)
(cherry picked from commit b7e2d67) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 65c32bb commit 09819ef

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

Objects/unicodeobject.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4256,7 +4256,7 @@ unicode_decode_call_errorhandler_writer(
42564256
}
42574257
if (need_to_grow) {
42584258
writer->overallocate = 1;
4259-
if (_PyUnicodeWriter_Prepare(writer, writer->min_length,
4259+
if (_PyUnicodeWriter_Prepare(writer, writer->min_length - writer->pos,
42604260
PyUnicode_MAX_CHAR_VALUE(repunicode)) == -1)
42614261
goto onError;
42624262
}
@@ -6085,9 +6085,7 @@ _PyUnicode_DecodeUnicodeEscape(const char *s,
60856085
&writer)) {
60866086
goto onError;
60876087
}
6088-
if (_PyUnicodeWriter_Prepare(&writer, writer.min_length, 127) < 0) {
6089-
goto onError;
6090-
}
6088+
assert(end - s <= writer.size - writer.pos);
60916089

60926090
#undef WRITE_ASCII_CHAR
60936091
#undef WRITE_CHAR
@@ -6364,9 +6362,7 @@ PyUnicode_DecodeRawUnicodeEscape(const char *s,
63646362
&writer)) {
63656363
goto onError;
63666364
}
6367-
if (_PyUnicodeWriter_Prepare(&writer, writer.min_length, 127) < 0) {
6368-
goto onError;
6369-
}
6365+
assert(end - s <= writer.size - writer.pos);
63706366

63716367
#undef WRITE_CHAR
63726368
}

0 commit comments

Comments
 (0)