Skip to content

Commit 4da93eb

Browse files
committed
pythongh-146196: Fix potential Undefined Behavior in
_PyUnicodeWriter_WriteASCIIString
1 parent d357a7d commit 4da93eb

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Objects/unicode_writer.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,9 @@ _PyUnicodeWriter_WriteASCIIString(_PyUnicodeWriter *writer,
465465
if (len == -1)
466466
len = strlen(ascii);
467467

468+
if (len == 0)
469+
return 0;
470+
468471
assert(ucs1lib_find_max_char((const Py_UCS1*)ascii, (const Py_UCS1*)ascii + len) < 128);
469472

470473
if (writer->buffer == NULL && !writer->overallocate) {
@@ -491,7 +494,7 @@ _PyUnicodeWriter_WriteASCIIString(_PyUnicodeWriter *writer,
491494
const Py_UCS1 *str = (const Py_UCS1 *)ascii;
492495
Py_UCS1 *data = writer->data;
493496

494-
memcpy(data + writer->pos, str, len);
497+
memmove(data + writer->pos, str, len);
495498
break;
496499
}
497500
case PyUnicode_2BYTE_KIND:

0 commit comments

Comments
 (0)