]> The Tcpdump Group git mirrors - tcpdump/commitdiff
From Gisle Vanem: give "tok2str()" 4 static buffers it can fill in, so
authorguy <guy>
Wed, 28 Apr 2004 22:09:23 +0000 (22:09 +0000)
committerguy <guy>
Wed, 28 Apr 2004 22:09:23 +0000 (22:09 +0000)
that it can be called up to 4 times in a given "printf()".

util.c

diff --git a/util.c b/util.c
index 4e3d61fc7941bea73bdb3509c9900eaeac4ca589..005824e369cc20cb88528b39da9637e92ccbf864 100644 (file)
--- a/util.c
+++ b/util.c
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.87.2.3 2003-12-29 22:42:23 hannes Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.87.2.4 2004-04-28 22:09:23 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -212,7 +212,9 @@ const char *
 tok2str(register const struct tok *lp, register const char *fmt,
        register int v)
 {
-       static char buf[128];
+       static char buf[4][128];
+       static int idx = 0;
+       char *ret;
 
        while (lp->s != NULL) {
                if (lp->v == v)
@@ -221,8 +223,10 @@ tok2str(register const struct tok *lp, register const char *fmt,
        }
        if (fmt == NULL)
                fmt = "#%d";
-       (void)snprintf(buf, sizeof(buf), fmt, v);
-       return (buf);
+       ret = buf[idx];
+       (void)snprintf(ret, sizeof(buf[0]), fmt, v);
+       idx = (idx+1) & 3;
+       return (ret);
 }
 
 /*