]> granicus.if.org Git - python/commitdiff
bpo-32827: Fix usage of _PyUnicodeWriter_Prepare() in decoding errors handler. (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 13 Feb 2018 07:15:57 +0000 (23:15 -0800)
committerSerhiy Storchaka <storchaka@gmail.com>
Tue, 13 Feb 2018 07:15:57 +0000 (09:15 +0200)
(cherry picked from commit b7e2d67f7c035f09c921ca4e7a36529cd502ccf7)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Objects/unicodeobject.c

index 3d9e09d7fab15836342b12adc6bedb8fe9351587..d5e7d10b1759edc015b1d55e8cdbad357d24910b 100644 (file)
@@ -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
     }