printbuf: preserve self-append sources across growth

When the appended data points into the printbuf itself, growing the buffer may invalidate the source pointer before it is copied. Preserve the source offset across realloc and use memmove for internal overlap.
This commit is contained in:
Darren Carreras
2026-08-01 14:12:56 -04:00
parent 1bd2e4b3ef
commit 62bb838c57
3 changed files with 49 additions and 1 deletions
+3
View File
@@ -21,6 +21,9 @@ Append to just after resize: 32, [XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX]
Buffer size after printbuf_strappend(): 16, [XXXXXXXXXXXXXXXX]
test_printbuf_memappend: end test
========================================
test_printbuf_self_append: starting test
test_printbuf_self_append: end test
========================================
test_sprintbuf: starting test
Buffer length: 0
sprintbuf to just after resize(31+1): 32, [XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX], strlen(buf)=32