From b430d48ab96bbd6bf931deead995962b05ec425f Mon Sep 17 00:00:00 2001 From: Dasperal Date: Sun, 8 Sep 2024 15:59:52 +0300 Subject: [PATCH] Fix vararg passthrough in the error message functions --- src/i_system.c | 67 ++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/src/i_system.c b/src/i_system.c index 609abdd11..9c802e7b2 100644 --- a/src/i_system.c +++ b/src/i_system.c @@ -252,72 +252,75 @@ void I_Quit(void) do_quit(false); } -void I_QuitWithError(char* error, ...) -{ - va_list argptr; - va_start(argptr, error); - I_AddError(error, argptr); - va_end(argptr); - - do_quit(true); -} - -void I_QuitWithMessage(char* error, ...) -{ - va_list argptr; - va_start(argptr, error); - I_AddMessage(error, argptr); - va_end(argptr); - - do_quit(false); -} - -void I_AddError(char* error, ...) +void _add_error(char* error, va_list argptr) { - va_list argptr; - // Message first. - va_start(argptr, error); vprintf(error, argptr); printf("\n\n"); - va_end(argptr); fflush(stdout); // Write a copy of the msg into buffer. message_t* msg = malloc(sizeof(message_t)); - va_start(argptr, error); memset(msg->msgbuf, 0, sizeof(msg->msgbuf)); M_vsnprintf(msg->msgbuf, sizeof(msg->msgbuf), error, argptr); - va_end(argptr); msg->type = SDL_MESSAGEBOX_ERROR; msg->next = message_queue; message_queue = msg; } -void I_AddMessage(char* message, ...) +void I_QuitWithError(char* error, ...) { va_list argptr; + va_start(argptr, error); + _add_error(error, argptr); + va_end(argptr); + do_quit(true); +} + +void I_AddError(char* error, ...) +{ + va_list argptr; + va_start(argptr, error); + _add_error(error, argptr); + va_end(argptr); +} + +void _add_message(char* message, va_list argptr) +{ // Message first. - va_start(argptr, message); vprintf(message, argptr); printf("\n\n"); - va_end(argptr); fflush(stdout); // Write a copy of the message into buffer. message_t* msg = malloc(sizeof(message_t)); - va_start(argptr, message); memset(msg->msgbuf, 0, sizeof(msg->msgbuf)); M_vsnprintf(msg->msgbuf, sizeof(msg->msgbuf), message, argptr); - va_end(argptr); msg->type = SDL_MESSAGEBOX_INFORMATION; msg->next = message_queue; message_queue = msg; } +void I_QuitWithMessage(char* error, ...) +{ + va_list argptr; + va_start(argptr, error); + _add_message(error, argptr); + va_end(argptr); + + do_quit(false); +} + +void I_AddMessage(char* message, ...) +{ + va_list argptr; + va_start(argptr, message); + _add_message(message, argptr); + va_end(argptr); +} // // I_Realloc