]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
com: detect truncation or error in dpvsnprintf()
authorbones_was_here <bones_was_here@xonotic.au>
Mon, 15 Jan 2024 00:41:06 +0000 (10:41 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Thu, 18 Jan 2024 06:58:47 +0000 (16:58 +1000)
Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
common.c

index 8db1f27025ab61c545583f0f2cba1821ab41ff6d..d479459c04fda307f730cb35342df8c11998223c 100644 (file)
--- a/common.c
+++ b/common.c
@@ -1000,6 +1000,11 @@ int dpvsnprintf (char *buffer, size_t buffersize, const char *format, va_list ar
        if (result < 0 || (size_t)result >= buffersize)
        {
                buffer[buffersize - 1] = '\0';
+               // we could be inside Con_Printf
+               if (result < 0)
+                       Sys_Printf("dpvsnprintf: output error, buffer size %zu\n", buffersize);
+               else
+                       Sys_Printf("dpvsnprintf: truncated to %zu bytes: \"%s\"\n", buffersize - 1, buffer);
                return -1;
        }