More <stdarg.h> cleanup; some are real bugs, some are just "don't do
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 26 May 2010 02:25:13 +0000 (02:25 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 26 May 2010 02:25:13 +0000 (02:25 +0000)
va_start and va_end unless you're actually going to use the va_list"
(those bring the va_start and va_end closer to the use point, which
makes it a little more obvious that we're using <stdarg.h> correctly and
makes it a little harder to use it incorrectly).

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@32963 f5534014-38df-0310-8fa8-9805f1628bb7

epan/dissectors/dcerpc/idl2wrs.c
epan/proto.c
tools/lemon/lemon.c
trigcap.c

index bccef64a0afb55756306838fc4a7c02a2932b3b0..2eba2b2e32b4edd4c91ce1705ebbf652e675d10d 100644 (file)
@@ -105,13 +105,17 @@ static char line[1024];
 static void FPRINTF(FILE *fh, const char *format, ...)
 {
        va_list args;
-       va_start(args, format);
+
 #ifdef IDL2WRS_DEBUG
+       va_start(args, format);
        vfprintf (stderr, format, args);
+       va_end(args);
 #endif
-       if (fh)
+       if (fh) {
+               va_start(args, format);
                vfprintf (fh, format, args);
-       va_end(args);
+               va_end(args);
+       }
 }
 
 typedef struct _pointer_item_t {
index 3864ae994e882890b993e5c7b688f27874685fc6..81a1a572231add5b3d75cb2c6f437b4ad56239e3 100644 (file)
@@ -1080,9 +1080,12 @@ proto_tree_add_debug_text(proto_tree *tree, const char *format, ...)
 
        pi = proto_tree_add_text_node(tree, NULL, 0, 0);
 
-       va_start(ap, format);
-       if (pi)
+       if (pi) {
+               va_start(ap, format);
                proto_tree_set_representation(pi, format, ap);
+               va_end(ap);
+       }
+       va_start(ap, format);
        vprintf(format, ap);
        va_end(ap);
        printf("\n");
@@ -3634,8 +3637,6 @@ proto_item_append_text(proto_item *pi, const char *format, ...)
        }
 
        if (!PROTO_ITEM_IS_HIDDEN(pi)) {
-               va_start(ap, format);
-
                /*
                 * If we don't already have a representation,
                 * generate the default representation.
@@ -3647,10 +3648,11 @@ proto_item_append_text(proto_item *pi, const char *format, ...)
 
                curlen = strlen(fi->rep->representation);
                if (ITEM_LABEL_LENGTH > curlen) {
+                       va_start(ap, format);
                        g_vsnprintf(fi->rep->representation + curlen,
                                ITEM_LABEL_LENGTH - (gulong) curlen, format, ap);
+                       va_end(ap);
                }
-               va_end(ap);
        }
 }
 
index 0facd5bdc35270fb43da80f44d0897481fa9373e..26961660ef2e3443aac60f25692bfe3a65abb48f 100644 (file)
@@ -1333,7 +1333,6 @@ void ErrorMsg(const char *filename, int lineno, const char *format, ...)
   va_list ap;
   int end, restart, base;
 
-  va_start(ap, format);
   /* Prepare a prefix to be prepended to every output line */
   if( lineno>0 ){
     sprintf(prefix,"%.*s:%d: ",PREFIXLIMIT-10,filename,lineno);
@@ -1344,6 +1343,7 @@ void ErrorMsg(const char *filename, int lineno, const char *format, ...)
   availablewidth = LINEWIDTH - prefixsize;
 
   /* Generate the error message */
+  va_start(ap, format);
   vsprintf(errmsg,format,ap);
   va_end(ap);
   errmsgsize = (int) strlen(errmsg);
index 9ecce1f8cc7f169d89fac73ed84a9d15da89fd60..394c50ad211f8aa4c415a118442c68f8098f3296 100644 (file)
--- a/trigcap.c
+++ b/trigcap.c
@@ -49,12 +49,12 @@ static void panic(int err, const char* fmt, ...) {
 static void dprintf(int lev, const char* fmt, ...) {
        va_list ap;
 
-       va_start(ap,fmt);
        if (lev <= debug_level) {
+               va_start(ap,fmt);
                vfprintf(stderr,fmt,ap);
+               va_end(ap);
                fflush(stderr);
        }
-       va_end(ap);
 }