Skip to content

Commit a05e17e

Browse files
committed
Fix buffer growth
1 parent 3652952 commit a05e17e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

mypyc/lib-rt/librt_strings.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ _grow_buffer(BytesWriterObject *data, Py_ssize_t n) {
4343
size *= 2;
4444
} while (target >= size);
4545
if (old_size == WRITER_EMBEDDED_BUF_LEN) {
46+
// Move from embedded buffer to heap-allocated buffer
4647
data->buf = PyMem_Malloc(size);
48+
if (data->buf != NULL) {
49+
memcpy(data->buf, data->data, WRITER_EMBEDDED_BUF_LEN);
50+
}
4751
} else {
4852
data->buf = PyMem_Realloc(data->buf, size);
4953
}

0 commit comments

Comments
 (0)