]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Use unsigned values in tok2str and bittok2str routines.
authorGuy Harris <[email protected]>
Sun, 19 Apr 2015 02:56:49 +0000 (19:56 -0700)
committerGuy Harris <[email protected]>
Sun, 19 Apr 2015 02:56:49 +0000 (19:56 -0700)
This prevents the compiler issue mentioned in GitHub issue #451, and
also cleans up some other signed vs. unsigned stuff.

While we're at it, clean up bittok2str_internal() (just pass it the
separator string, not a Boolean value that's tested to choose the
separator string), and print unknown arguments to the bittok2str
routines in hex, not decimal.

netdissect.h
util-print.c

index f4de98cd2726f32ed3355d94151151eb97fa6f5f..be78857e5afe1271c69d5d2e21ec1fcd363c573c 100644 (file)
@@ -81,9 +81,9 @@ extern const char *tok2strbuf(const struct tok *, const char *, u_int,
                              char *buf, size_t bufsize);
 
 /* tok2str is deprecated */
-extern const char *tok2str(const struct tok *, const char *, int);
-extern char *bittok2str(const struct tok *, const char *, int);
-extern char *bittok2str_nosep(const struct tok *, const char *, int);
+extern const char *tok2str(const struct tok *, const char *, u_int);
+extern char *bittok2str(const struct tok *, const char *, u_int);
+extern char *bittok2str_nosep(const struct tok *, const char *, u_int);
 
 
 typedef struct netdissect_options netdissect_options;
@@ -293,7 +293,6 @@ extern void relts_print(netdissect_options *, int);
 extern int fn_print(netdissect_options *, const u_char *, const u_char *);
 extern int fn_printn(netdissect_options *, const u_char *, u_int, const u_char *);
 extern int fn_printzp(netdissect_options *, const u_char *, u_int, const u_char *);
-extern const char *tok2str(const struct tok *, const char *, int);
 
 /*
  * Flags for txtproto_print().
index 4909c64acee920f9fc7f79a16544776802ec55b0..2c3eb6597feef9ab593cb8c492ed04ac0521c2e6 100644 (file)
@@ -338,7 +338,7 @@ tok2strbuf(register const struct tok *lp, register const char *fmt,
  */
 const char *
 tok2str(register const struct tok *lp, register const char *fmt,
-       register int v)
+       register u_int v)
 {
        static char buf[4][128];
        static int idx = 0;
@@ -356,12 +356,12 @@ tok2str(register const struct tok *lp, register const char *fmt,
  */
 static char *
 bittok2str_internal(register const struct tok *lp, register const char *fmt,
-          register int v, register int sep)
+          register u_int v, const char *sep)
 {
         static char buf[256]; /* our stringbuffer */
         int buflen=0;
-        register int rotbit; /* this is the bit we rotate through all bitpositions */
-        register int tokval;
+        register u_int rotbit; /* this is the bit we rotate through all bitpositions */
+        register u_int tokval;
         const char * sepstr = "";
 
        while (lp != NULL && lp->s != NULL) {
@@ -376,7 +376,7 @@ bittok2str_internal(register const struct tok *lp, register const char *fmt,
                     /* ok we have found something */
                     buflen+=snprintf(buf+buflen, sizeof(buf)-buflen, "%s%s",
                                      sepstr, lp->s);
-                    sepstr = sep ? ", " : "";
+                    sepstr = sep;
                     break;
                 }
                 rotbit=rotbit<<1; /* no match - lets shift and try again */
@@ -386,7 +386,7 @@ bittok2str_internal(register const struct tok *lp, register const char *fmt,
 
         if (buflen == 0)
             /* bummer - lets print the "unknown" message as advised in the fmt string if we got one */
-            (void)snprintf(buf, sizeof(buf), fmt == NULL ? "#%d" : fmt, v);
+            (void)snprintf(buf, sizeof(buf), fmt == NULL ? "#%08x" : fmt, v);
         return (buf);
 }
 
@@ -396,9 +396,9 @@ bittok2str_internal(register const struct tok *lp, register const char *fmt,
  */
 char *
 bittok2str_nosep(register const struct tok *lp, register const char *fmt,
-          register int v)
+          register u_int v)
 {
-    return (bittok2str_internal(lp, fmt, v, 0));
+    return (bittok2str_internal(lp, fmt, v, ""));
 }
 
 /*
@@ -407,9 +407,9 @@ bittok2str_nosep(register const struct tok *lp, register const char *fmt,
  */
 char *
 bittok2str(register const struct tok *lp, register const char *fmt,
-          register int v)
+          register u_int v)
 {
-    return (bittok2str_internal(lp, fmt, v, 1));
+    return (bittok2str_internal(lp, fmt, v, ", "));
 }
 
 /*