common: Call va_end after vfprintf in PluginLog

The C spec states that the va_arg argument value is indeterminate after
returning from vfprintf. va_end and va_start must be called before the
variable is reused.
This commit is contained in:
Jonathan Li 2018-06-22 01:20:40 +01:00
parent ba1689f6d6
commit fa7822fbbf
1 changed files with 19 additions and 16 deletions

View File

@ -86,38 +86,41 @@ struct PluginLog
void Write(const char *fmt, ...)
{
va_list list;
if (LogFile == NULL)
return;
va_list list;
if (WriteToFile) {
va_start(list, fmt);
if (WriteToFile)
vfprintf(LogFile, fmt, list);
if (WriteToConsole)
va_end(list);
}
if (WriteToConsole) {
va_start(list, fmt);
vfprintf(stdout, fmt, list);
va_end(list);
}
}
void WriteLn(const char *fmt, ...)
{
va_list list;
if (LogFile == NULL)
return;
va_list list;
if (WriteToFile) {
va_start(list, fmt);
if (WriteToFile)
vfprintf(LogFile, fmt, list);
if (WriteToConsole)
va_end(list);
fprintf(LogFile, "\n");
}
if (WriteToConsole) {
va_start(list, fmt);
vfprintf(stdout, fmt, list);
va_end(list);
if (WriteToFile)
fprintf(LogFile, "\n");
if (WriteToConsole)
fprintf(stdout, "\n");
}
}
#if !defined(_MSC_VER) || !defined(UNICODE)
void Message(const char *fmt, ...)