From 83eea6075b8f4746d632a792b1d1b97c19797acb Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Fri, 7 Aug 2020 17:04:04 -0700 Subject: [PATCH] change errorv calling convention to explicitly take a format string This function implicitly assumed its variable arguments contained a format string as the first argument. This change pushes the assumption into the calling convention, making it visible to the compiler. --- lib/ast/error.c | 12 +++++++----- lib/ast/error.h | 2 +- lib/gvpr/gvpr.c | 4 +++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/ast/error.c b/lib/ast/error.c index 8d98682ef..983938255 100644 --- a/lib/ast/error.c +++ b/lib/ast/error.c @@ -40,9 +40,8 @@ void setErrorErrors (int errors) { error_info.errors = errors; } int getErrorErrors () { return error_info.errors; } void setTraceLevel (int i) { error_info.trace = i; } -void errorv(const char *id, int level, va_list ap) +void errorv(const char *id, int level, const char *s, va_list ap) { - const char *s; int flags; if (level < error_info.trace) return; @@ -80,7 +79,6 @@ void errorv(const char *id, int level, va_list ap) sfprintf(sfstderr, "line %d: ", error_info.line); } } - s = va_arg(ap, char *); sfvprintf(sfstderr, s, ap); if (flags & ERROR_SYSTEM) sfprintf(sfstderr, "\n%s", strerror(errno)); @@ -92,18 +90,22 @@ void errorv(const char *id, int level, va_list ap) void error(int level, ...) { va_list ap; + const char *s; va_start(ap, level); - errorv(NiL, level, ap); + s = va_arg(ap, char *); + errorv(NiL, level, s, ap); va_end(ap); } void errorf(void *handle, void *discipline, int level, ...) { va_list ap; + const char *s; va_start(ap, level); + s = va_arg(ap, char *); errorv((discipline - && handle) ? *((char **) handle) : (char *) handle, level, ap); + && handle) ? *((char **) handle) : (char *) handle, level, s, ap); va_end(ap); } diff --git a/lib/ast/error.h b/lib/ast/error.h index 58106b07e..47b0a681c 100644 --- a/lib/ast/error.h +++ b/lib/ast/error.h @@ -64,7 +64,7 @@ extern "C" { extern void error(int, ...); extern void errorf(void *, void *, int, ...); - extern void errorv(const char *, int, va_list); + extern void errorv(const char *, int, const char *, va_list); #endif diff --git a/lib/gvpr/gvpr.c b/lib/gvpr/gvpr.c index d3e08b0cb..ce8c26f0a 100644 --- a/lib/gvpr/gvpr.c +++ b/lib/gvpr/gvpr.c @@ -906,10 +906,12 @@ static int gverrorf (Expr_t *handle, Exdisc_t *discipline, int level, ...) { va_list ap; + const char *s; va_start(ap, level); + s = va_arg(ap, char *); errorv((discipline - && handle) ? *((char **) handle) : (char *) handle, level, ap); + && handle) ? *((char **) handle) : (char *) handle, level, s, ap); va_end(ap); if (level >= ERROR_ERROR) { -- 2.40.0