]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Handle va_list correctly in fatal() when also writing to log file
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 9 May 2010 18:00:09 +0000 (20:00 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 9 May 2010 18:00:09 +0000 (20:00 +0200)
util.c

diff --git a/util.c b/util.c
index 4ac7109057ee9fc68edb7a81eb6993de61d5c19c..ccbbc5a6f0208bcbe68600b1f8add6723311e80a 100644 (file)
--- 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);
 }