From 774a9f440bebeea960b69bb46109d72b3d7b8667 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 17 Apr 2026 19:52:53 +0200 Subject: [PATCH] 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()). --- src/basic/strxcpyx.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/basic/strxcpyx.c b/src/basic/strxcpyx.c index dc40d620e7..f8410f7d0c 100644 --- a/src/basic/strxcpyx.c +++ b/src/basic/strxcpyx.c @@ -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;