utf8: refactor `strbuf_utf8_replace` to not rely on preallocated buffer
commitf930a2394303b902e2973f4308f96529f736b8bc
authorPatrick Steinhardt <ps@pks.im>
Thu, 1 Dec 2022 14:47:15 +0000 (1 15:47 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 9 Dec 2022 05:26:21 +0000 (9 14:26 +0900)
treeda1d18e7ea7b15b5239af1aeffbb051b68a35f23
parent81c2d4c3a5ba0e6ab8c348708441fed170e63a82
utf8: refactor `strbuf_utf8_replace` to not rely on preallocated buffer

In `strbuf_utf8_replace`, we preallocate the destination buffer and then
use `memcpy` to copy bytes into it at computed offsets. This feels
rather fragile and is hard to understand at times. Refactor the code to
instead use `strbuf_add` and `strbuf_addstr` so that we can be sure that
there is no possibility to perform an out-of-bounds write.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
utf8.c