Skip to content

Commit

Permalink
fix(liblogging): copy va_args before reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
hparzych committed Oct 5, 2023
1 parent 0a9c0bb commit 234c023
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions liblogging/src/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ void Logger::vlogf(enum LogLevel level, const char* format, va_list args) {
const int staticBufSize = 512;
static char staticBuf[staticBufSize]{};

static va_list argsCopy;
va_copy(argsCopy, args);

int resultSize = vsnprintf(staticBuf, staticBufSize, format, args);
if (resultSize <= staticBufSize) {
logLine(level, staticBuf, resultSize);
return;
}

static va_list args2;
va_copy(args2, args);

char buf[resultSize]{};
vsnprintf(buf, resultSize, format, args2);
vsnprintf(buf, resultSize, format, argsCopy);

logLine(level, buf, resultSize);
}
Expand Down Expand Up @@ -116,5 +116,4 @@ void Logger::logLine(enum LogLevel level, const char* buf, size_t len) {
}
log(level, "{}", str);
}

} // namespace logging

0 comments on commit 234c023

Please sign in to comment.