From 21fa9010ae6de8792f36cca08cb77aaa95d4b928 Mon Sep 17 00:00:00 2001 From: bones_was_here Date: Mon, 15 Jan 2024 10:41:06 +1000 Subject: [PATCH] com: detect truncation or error in dpvsnprintf() Signed-off-by: bones_was_here --- common.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/common.c b/common.c index 8db1f270..d479459c 100644 --- 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; } -- 2.39.2