Skip to content

Commit

Permalink
bpo-32827: Fix usage of _PyUnicodeWriter_Prepare() in decoding errors…
Browse files Browse the repository at this point in the history
… handler. (GH-5636) (GH-5650)

(cherry picked from commit b7e2d67)


Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
  • Loading branch information
miss-islington and serhiy-storchaka committed Feb 13, 2018
1 parent 65c32bb commit 09819ef
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions Objects/unicodeobject.c
Expand Up @@ -4256,7 +4256,7 @@ unicode_decode_call_errorhandler_writer(
}
if (need_to_grow) {
writer->overallocate = 1;
if (_PyUnicodeWriter_Prepare(writer, writer->min_length,
if (_PyUnicodeWriter_Prepare(writer, writer->min_length - writer->pos,
PyUnicode_MAX_CHAR_VALUE(repunicode)) == -1)
goto onError;
}
Expand Down Expand Up @@ -6085,9 +6085,7 @@ _PyUnicode_DecodeUnicodeEscape(const char *s,
&writer)) {
goto onError;
}
if (_PyUnicodeWriter_Prepare(&writer, writer.min_length, 127) < 0) {
goto onError;
}
assert(end - s <= writer.size - writer.pos);

#undef WRITE_ASCII_CHAR
#undef WRITE_CHAR
Expand Down Expand Up @@ -6364,9 +6362,7 @@ PyUnicode_DecodeRawUnicodeEscape(const char *s,
&writer)) {
goto onError;
}
if (_PyUnicodeWriter_Prepare(&writer, writer.min_length, 127) < 0) {
goto onError;
}
assert(end - s <= writer.size - writer.pos);

#undef WRITE_CHAR
}
Expand Down

0 comments on commit 09819ef

Please sign in to comment.