strxcpyx: add a paranoia check for vsnprintf()'s return value

vsnprintf() can, under some circumstances, return negative value, namely
during encoding errors when converting wchars to multi-byte characters.
This would then wreak havoc in the arithmetics we do following the
vsnprintf() call. However, since we never do any wchar shenanigans in
our code it should never happen.

Let's encode this assumption into the code as an assert(), similarly how
we already do this in other places (like strextendf_with_separator()).
This commit is contained in:
Frantisek Sumsal
2026-04-19 14:06:15 +02:00
parent c859d41232
commit 774a9f440b
+2
View File
@@ -64,6 +64,8 @@ size_t strpcpyf_full(char **dest, size_t size, bool *ret_truncated, const char *
i = vsnprintf(*dest, size, src, va);
va_end(va);
assert(i >= 0);
if (i < (int) size) {
*dest += i;
size -= i;