summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Objects/stringlib/codecs.h
diff options
context:
space:
mode:
authorarcadia-devtools <[email protected]>2022-06-09 19:02:01 +0300
committerarcadia-devtools <[email protected]>2022-06-09 19:02:01 +0300
commit4a29d649866ff133e0b8f8a1009e1000a44d7279 (patch)
tree547229aded91b3760628c646a144af604f1c3e2b /contrib/tools/python3/src/Objects/stringlib/codecs.h
parent782f2445a283aed9a66e699137b3349af1689c29 (diff)
intermediate changes
ref:478170c7a5a1c0788ddd0d6513ce4ed86d7d7c99
Diffstat (limited to 'contrib/tools/python3/src/Objects/stringlib/codecs.h')
-rw-r--r--contrib/tools/python3/src/Objects/stringlib/codecs.h15
1 files changed, 13 insertions, 2 deletions
diff --git a/contrib/tools/python3/src/Objects/stringlib/codecs.h b/contrib/tools/python3/src/Objects/stringlib/codecs.h
index b17cda18f54..958cc861478 100644
--- a/contrib/tools/python3/src/Objects/stringlib/codecs.h
+++ b/contrib/tools/python3/src/Objects/stringlib/codecs.h
@@ -387,8 +387,19 @@ STRINGLIB(utf8_encoder)(_PyBytesWriter *writer,
if (!rep)
goto error;
- /* subtract preallocated bytes */
- writer->min_size -= max_char_size * (newpos - startpos);
+ if (newpos < startpos) {
+ writer->overallocate = 1;
+ p = _PyBytesWriter_Prepare(writer, p,
+ max_char_size * (startpos - newpos));
+ if (p == NULL)
+ goto error;
+ }
+ else {
+ /* subtract preallocated bytes */
+ writer->min_size -= max_char_size * (newpos - startpos);
+ /* Only overallocate the buffer if it's not the last write */
+ writer->overallocate = (newpos < size);
+ }
if (PyBytes_Check(rep)) {
p = _PyBytesWriter_WriteBytes(writer, p,