Fix logging crash, using a va_list twice.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@12809 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
curaga
2013-05-30 12:35:41 +00:00
parent 7d4c2bc33e
commit 7986aa66de

View File

@@ -156,6 +156,14 @@ void Log::printMessage(int level, const char *component, const char *format,
static const char *names[] = {"verbose", "debug ", "info ",
"warn ", "error ", "fatal "};
// Using a va_list twice produces undefined results, ie crash.
// So make a copy if we're going to use it twice.
VALIST copy;
if (m_file_stdout && UserConfigParams::m_log_errors_to_console)
{
va_copy(copy, va_list);
}
// If we don't have a console file, write to stdout and hope for the best
if(!m_file_stdout ||
UserConfigParams::m_log_errors_to_console) // log to console & file
@@ -168,8 +176,9 @@ void Log::printMessage(int level, const char *component, const char *format,
if(m_file_stdout)
{
fprintf (m_file_stdout, "[%s] %s: ", names[level], component);
vfprintf(m_file_stdout, format, va_list);
vfprintf(m_file_stdout, format, copy);
fprintf (m_file_stdout, "\n");
va_end(copy);
}
#endif