From 0fc7fd5d33b509cb10e91ee987b6f3602f540660 Mon Sep 17 00:00:00 2001 From: George Koehler Date: Wed, 24 Oct 2012 13:44:50 -0400 Subject: [PATCH] Prevent segfault when trying to print an error message. Use to pass arguments correctly, as ack/util/util.c already uses the same way. --- util/led/error.c | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/util/led/error.c b/util/led/error.c index 7f7a53749..e7f4fc6ec 100644 --- a/util/led/error.c +++ b/util/led/error.c @@ -6,13 +6,14 @@ static char rcsid[] = "$Id$"; #endif +#include #include #include #include #include "const.h" static short nerrors = 0; -static diag(); +static void diag(char *, char *, va_list); stop() { @@ -28,40 +29,49 @@ stop() } /* VARARGS1 */ -fatal(format, a1, a2, a3, a4) - char *format; +void +fatal(char *format, ...) { + va_list ap; + va_start(ap, format); nerrors++; - diag("fatal", format, a1, a2, a3, a4); + diag("fatal", format, ap); stop(); } /* VARARGS1 */ -warning(format, a1, a2, a3, a4) - char *format; +void +warning(char *format, ...) { - diag("warning", format, a1, a2, a3, a4); + va_list ap; + va_start(ap, format); + diag("warning", format, ap); + va_end(ap); } /* VARARGS1 */ -error(format, a1, a2, a3, a4) - char *format; +void +error(char *format, ...) { + va_list ap; + va_start(ap, format); nerrors++; - diag("error", format, a1, a2, a3, a4); + diag("error", format, ap); + va_end(ap); } /* VARARGS1 */ -do_verbose(format, a1, a2, a3, a4) - char *format; +void +do_verbose(char *format, ...) { - diag((char *) 0, format, a1, a2, a3, a4); + va_list ap; + va_start(ap, format); + diag((char *) 0, format, ap); + va_end(ap); } -static -diag(tail, format, a1, a2, a3, a4) - char *tail; - char *format; +static void +diag(char *tail, char *format, va_list ap) { extern char *progname, *archname, *modulname; @@ -72,7 +82,7 @@ diag(tail, format, a1, a2, a3, a4) fprintf(stderr, "%s: ", archname); else if (modulname) fprintf(stderr, "%s: ", modulname); - fprintf(stderr, format, a1, a2, a3, a4); + vfprintf(stderr, format, ap); if (tail) fprintf(stderr, " (%s)\n", tail); else putc('\n', stderr); }