| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -350,8 +350,6 @@ STRINGLIB(utf8_encoder)(PyObject *unicode, | |||
| 350 | 350 | break; | |
| 351 | 351 | ||
| 352 | 352 | case _Py_ERROR_BACKSLASHREPLACE: | |
| 353 | - /* subtract preallocated bytes */ | ||
| 354 | - writer->size -= max_char_size * (endpos - startpos); | ||
| 355 | 353 | p = backslashreplace(writer, p, | |
| 356 | 354 | unicode, startpos, endpos); | |
| 357 | 355 | if (p == NULL) | |
@@ -360,8 +358,6 @@ STRINGLIB(utf8_encoder)(PyObject *unicode, | |||
| 360 | 358 | break; | |
| 361 | 359 | ||
| 362 | 360 | case _Py_ERROR_XMLCHARREFREPLACE: | |
| 363 | - /* subtract preallocated bytes */ | ||
| 364 | - writer->size -= max_char_size * (endpos - startpos); | ||
| 365 | 361 | p = xmlcharrefreplace(writer, p, | |
| 366 | 362 | unicode, startpos, endpos); | |
| 367 | 363 | if (p == NULL) | |
@@ -400,10 +396,15 @@ STRINGLIB(utf8_encoder)(PyObject *unicode, | |||
| 400 | 396 | } | |
| 401 | 397 | } | |
| 402 | 398 | else { | |
| 403 | - /* subtract preallocated bytes */ | ||
| 404 | - writer->size -= max_char_size * (newpos - startpos); | ||
| 405 | 399 | /* Only overallocate the buffer if it's not the last write */ | |
| 406 | 400 | writer->overallocate = (newpos < size); | |
| 401 | + | ||
| 402 | + /* subtract preallocated bytes */ | ||
| 403 | + Py_ssize_t prealloc = max_char_size * (newpos - startpos); | ||
| 404 | + p = PyBytesWriter_GrowAndUpdatePointer(writer, -prealloc, p); | ||
| 405 | + if (p == NULL) { | ||
| 406 | + goto error; | ||
| 407 | + } | ||
| 407 | 408 | } | |
| 408 | 409 | ||
| 409 | 410 | const char *rep_str; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments