From 66f175d54d03d4b380698a8d896fa9c942001e2b Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Sun, 9 May 2010 20:00:09 +0200 Subject: [PATCH] Handle va_list correctly in fatal() when also writing to log file --- util.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/util.c b/util.c index 4ac710905..ccbbc5a6f 100644 --- a/util.c +++ b/util.c @@ -66,25 +66,24 @@ void fatal(const char *format, ...) { va_list ap; extern char *cache_logfile; + char msg[1000]; va_start(ap, format); + vsnprintf(msg, sizeof(msg), format, ap); + va_end(ap); if (cache_logfile) { if (!logfile) { logfile = fopen(cache_logfile, "a"); } if (logfile) { - fprintf(logfile, "[%-5d] FATAL: ", getpid()); - vfprintf(logfile, format, ap); + fprintf(logfile, "[%-5d] FATAL: %s", getpid(), msg); fflush(logfile); } } - fprintf(stderr, "ccache: FATAL: "); - vfprintf(stderr, format, ap); - fprintf(stderr, "\n"); + fprintf(stderr, "ccache: FATAL: %s\n", msg); - va_end(ap); exit(1); } -- 2.47.2