File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -350,6 +350,8 @@ 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 );
353
355
p = backslashreplace (writer , p ,
354
356
unicode , startpos , endpos );
355
357
if (p == NULL )
@@ -358,6 +360,8 @@ STRINGLIB(utf8_encoder)(PyObject *unicode,
358
360
break ;
359
361
360
362
case _Py_ERROR_XMLCHARREFREPLACE :
363
+ /* subtract preallocated bytes */
364
+ writer -> size -= max_char_size * (endpos - startpos );
361
365
p = xmlcharrefreplace (writer , p ,
362
366
unicode , startpos , endpos );
363
367
if (p == NULL )
@@ -396,6 +400,8 @@ STRINGLIB(utf8_encoder)(PyObject *unicode,
396
400
}
397
401
}
398
402
else {
403
+ /* subtract preallocated bytes */
404
+ writer -> size -= max_char_size * (newpos - startpos );
399
405
/* Only overallocate the buffer if it's not the last write */
400
406
writer -> overallocate = (newpos < size );
401
407
}
Original file line number Diff line number Diff line change @@ -7414,6 +7414,8 @@ unicode_encode_ucs1(PyObject *unicode,
7414
7414
break ;
7415
7415
7416
7416
case _Py_ERROR_BACKSLASHREPLACE :
7417
+ /* subtract preallocated bytes */
7418
+ writer -> size -= (collend - collstart );
7417
7419
str = backslashreplace (writer , str ,
7418
7420
unicode , collstart , collend );
7419
7421
if (str == NULL )
@@ -7422,6 +7424,8 @@ unicode_encode_ucs1(PyObject *unicode,
7422
7424
break ;
7423
7425
7424
7426
case _Py_ERROR_XMLCHARREFREPLACE :
7427
+ /* subtract preallocated bytes */
7428
+ writer -> size -= (collend - collstart );
7425
7429
str = xmlcharrefreplace (writer , str ,
7426
7430
unicode , collstart , collend );
7427
7431
if (str == NULL )
@@ -7462,6 +7466,8 @@ unicode_encode_ucs1(PyObject *unicode,
7462
7466
}
7463
7467
}
7464
7468
else {
7469
+ /* subtract preallocated bytes */
7470
+ writer -> size -= newpos - collstart ;
7465
7471
/* Only overallocate the buffer if it's not the last write */
7466
7472
writer -> overallocate = (newpos < size );
7467
7473
}
You can’t perform that action at this time.
0 commit comments