From 4f1762b694b68fd2c362f32a332ec22b7fa95207 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 22 Mar 2026 22:29:10 +0100 Subject: [PATCH] split CONS_Printf so both CONS_Alert and CONS_Debug dont have to handle and copy the varargs twice probably makes no actual difference in practice, but i prefer it to not do pointless work --- src/console.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/console.c b/src/console.c index 6fb3294f1..be9b1565b 100644 --- a/src/console.c +++ b/src/console.c @@ -1182,19 +1182,10 @@ void CON_LogMessage(const char *msg) // Console print! Wahooo! Lots o fun! // -void CONS_Printf(const char *fmt, ...) +static inline void CONS_PrintMsg(char *txt) { - va_list argptr; - static char *txt = NULL; boolean startup; - if (txt == NULL) - txt = malloc(8192); - - va_start(argptr, fmt); - vsnprintf(txt, 8192, fmt, argptr); - va_end(argptr); - // echo console prints to log file DEBFILE(txt); @@ -1220,6 +1211,21 @@ void CONS_Printf(const char *fmt, ...) } } +void CONS_Printf(const char *fmt, ...) +{ + va_list argptr; + static char *txt = NULL; + + if (txt == NULL) + txt = malloc(8192); + + va_start(argptr, fmt); + vsnprintf(txt, 8192, fmt, argptr); + va_end(argptr); + + CONS_PrintMsg(txt); +} + void CONS_Alert(alerttype_t level, const char *fmt, ...) { va_list argptr; @@ -1248,9 +1254,7 @@ void CONS_Alert(alerttype_t level, const char *fmt, ...) break; } - // I am lazy and I feel like just letting CONS_Printf take care of things. - // Is that okay? - CONS_Printf("%s", txt); + CONS_PrintMsg(txt); } void CONS_Debug(INT32 debugflags, const char *fmt, ...) @@ -1268,11 +1272,9 @@ void CONS_Debug(INT32 debugflags, const char *fmt, ...) vsnprintf(txt, 8192, fmt, argptr); va_end(argptr); - // Again I am lazy, oh well - CONS_Printf("%s", txt); + CONS_PrintMsg(txt); } - // Print an error message, and wait for ENTER key to continue. // To make sure the user has seen the message //