Skip to content

Commit

Permalink
Fix variable arguments start/end
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven-Roberts committed Jul 30, 2024
1 parent b67a3cb commit 6edb858
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
6 changes: 4 additions & 2 deletions include/sundials/priv/sundials_errors_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,12 @@ static inline void SUNHandleErrWithFmtMsg(int line, const char* func,
msglen = (size_t)vsnprintf(NULL, (size_t)0, msgfmt, values); /* determine size
of buffer
needed */
msg = (char*)malloc(msglen + 1);
va_end(values);
msg = (char*)malloc(msglen + 1);
va_start(values, sunctx);
vsnprintf(msg, msglen + 1, msgfmt, values);
SUNHandleErrWithMsg(line, func, file, msg, code, sunctx);
va_end(values);
SUNHandleErrWithMsg(line, func, file, msg, code, sunctx);
free(msg);
}

Expand Down
8 changes: 4 additions & 4 deletions src/sundials/sundials_errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,23 @@ void SUNGlobalFallbackErrHandler(int line, const char* func, const char* file,
char* log_msg = NULL;
char* file_and_line = NULL;

va_start(ap, err_code);

file_and_line = sunCombineFileAndLine(__LINE__, __FILE__);
va_start(ap, err_code);
sunCreateLogMessage(SUN_LOGLEVEL_ERROR, 0, file_and_line,
__func__, "The SUNDIALS SUNContext was corrupt or NULL when an error occurred. As such, error messages have been printed to stderr.",
ap, &log_msg);
va_end(ap);
fprintf(stderr, "%s", log_msg);
free(log_msg);
free(file_and_line);

file_and_line = sunCombineFileAndLine(line, file);
if (msgfmt == NULL) { msgfmt = SUNGetErrMsg(err_code); }
va_start(ap, err_code);
sunCreateLogMessage(SUN_LOGLEVEL_ERROR, 0, file_and_line, func, msgfmt, ap,
&log_msg);
va_end(ap);
fprintf(stderr, "%s", log_msg);
free(log_msg);
free(file_and_line);

va_end(ap);
}
11 changes: 6 additions & 5 deletions src/sundials/sundials_logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,12 @@ SUNErrCode SUNLogger_QueueMsg(SUNLogger logger, SUNLogLevel lvl,
return retval;
}

va_list args;
va_start(args, msg_txt);

if (logger->queuemsg)
{
va_list args;
va_start(args, msg_txt);
retval = logger->queuemsg(logger, lvl, scope, label, msg_txt, args);
va_end(args);
}
else
{
Expand All @@ -347,7 +347,10 @@ SUNErrCode SUNLogger_QueueMsg(SUNLogger logger, SUNLogLevel lvl,
if (sunLoggerIsOutputRank(logger, &rank))
{
char* log_msg = NULL;
va_list args;
va_start(args, msg_txt);
sunCreateLogMessage(lvl, rank, scope, label, msg_txt, args, &log_msg);
va_end(args);

switch (lvl)
{
Expand All @@ -372,8 +375,6 @@ SUNErrCode SUNLogger_QueueMsg(SUNLogger logger, SUNLogLevel lvl,
free(log_msg);
}
}

va_end(args);
}
#else
/* silence warnings when all logging is disabled */
Expand Down

0 comments on commit 6edb858

Please sign in to comment.