Skip to content

Commit

Permalink
Fix vararg passthrough in the error message functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Dasperal committed Sep 8, 2024
1 parent f0c3b35 commit b430d48
Showing 1 changed file with 35 additions and 32 deletions.
67 changes: 35 additions & 32 deletions src/i_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b430d48

Please sign in to comment.