summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-02-13 06:27:33 (GMT)
committerGitHub <noreply@github.com>2018-02-13 06:27:33 (GMT)
commitb7e2d67f7c035f09c921ca4e7a36529cd502ccf7 (patch)
tree4587c06804f87baacc8edf3be772b0046f4d1ea0
parent688722cedd6437910ff185ecf94fb3b749ad37f2 (diff)
downloadcpython-b7e2d67f7c035f09c921ca4e7a36529cd502ccf7.zip
cpython-b7e2d67f7c035f09c921ca4e7a36529cd502ccf7.tar.gz
cpython-b7e2d67f7c035f09c921ca4e7a36529cd502ccf7.tar.bz2
bpo-32827: Fix usage of _PyUnicodeWriter_Prepare() in decoding errors handler. (GH-5636)
-rw-r--r--Objects/unicodeobject.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index f5e4ab6..0233438 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -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;
}
@@ -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
@@ -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
}