From 4a29d649866ff133e0b8f8a1009e1000a44d7279 Mon Sep 17 00:00:00 2001 From: arcadia-devtools Date: Thu, 9 Jun 2022 19:02:01 +0300 Subject: intermediate changes ref:478170c7a5a1c0788ddd0d6513ce4ed86d7d7c99 --- contrib/tools/python3/src/Objects/stringlib/codecs.h | 15 +++++++++++++-- contrib/tools/python3/src/Objects/stringlib/fastsearch.h | 3 ++- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'contrib/tools/python3/src/Objects/stringlib') 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, diff --git a/contrib/tools/python3/src/Objects/stringlib/fastsearch.h b/contrib/tools/python3/src/Objects/stringlib/fastsearch.h index 6574720b609..7b8be5d6492 100644 --- a/contrib/tools/python3/src/Objects/stringlib/fastsearch.h +++ b/contrib/tools/python3/src/Objects/stringlib/fastsearch.h @@ -4,7 +4,8 @@ /* fast search/count implementation, based on a mix between boyer- moore and horspool, with a few more bells and whistles on the top. - for some more background, see: http://effbot.org/zone/stringlib.htm */ + for some more background, see: + https://web.archive.org/web/20201107074620/http://effbot.org/zone/stringlib.htm */ /* note: fastsearch may access s[n], which isn't a problem when using Python's ordinary string types, but may cause problems if you're -- cgit v1.3