From: Ivan Maidanski Date: Mon, 12 Sep 2016 18:55:25 +0000 (+0300) Subject: Workaround 'va_list used before va_start' cppcheck error in cord X-Git-Tag: v8.0.0~1157 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=accb6d2ef4a4632176083e892c5990541f1f9d9a;p=gc Workaround 'va_list used before va_start' cppcheck error in cord Note that -D CPPCHECK should be passed to cppcheck to activate this workaround. * cord/cordprnt.c (CORD_vsprintf) [CPPCHECK]: Force to use va_copy and va_end. * cord/cordprnt.c (CORD_vsprintf): Set res to -1 if invalid format specifier (instead of immediate return -1); call va_end at a single place. --- diff --git a/cord/cordprnt.c b/cord/cordprnt.c index 8f91cb86..d3a85da6 100644 --- a/cord/cordprnt.c +++ b/cord/cordprnt.c @@ -272,16 +272,17 @@ int CORD_vsprintf(CORD * out, CORD format, va_list args) register char * buf; va_list vsprintf_args; int max_size = 0; - int res; -# ifdef __va_copy + int res = 0; + +# if defined(CPPCHECK) + va_copy(vsprintf_args, args); +# elif defined(__va_copy) __va_copy(vsprintf_args, args); -# else -# if defined(__GNUC__) && !defined(__DJGPP__) \ +# elif defined(__GNUC__) && !defined(__DJGPP__) \ && !defined(__EMX__) /* and probably in other cases */ - va_copy(vsprintf_args, args); -# else - vsprintf_args = args; -# endif + va_copy(vsprintf_args, args); +# else + vsprintf_args = args; # endif if (width == VARIABLE) width = va_arg(args, int); if (prec == VARIABLE) prec = va_arg(args, int); @@ -324,15 +325,11 @@ int CORD_vsprintf(CORD * out, CORD format, va_list args) (void) va_arg(args, double); break; default: -# if defined(__va_copy) \ - || (defined(__GNUC__) && !defined(__DJGPP__) \ - && !defined(__EMX__)) - va_end(vsprintf_args); -# endif - return(-1); + res = -1; } - res = vsprintf(buf, conv_spec, vsprintf_args); -# if defined(__va_copy) \ + if (0 == res) + res = vsprintf(buf, conv_spec, vsprintf_args); +# if defined(CPPCHECK) || defined(__va_copy) \ || (defined(__GNUC__) && !defined(__DJGPP__) \ && !defined(__EMX__)) va_end(vsprintf_args);