tcpdump mailing list archives
tok2str() patch
From: "Gisle Vanem" <giva () bgnett no>
Date: Wed, 24 Mar 2004 20:26:19 +0100
tok2str() is in several files used multiple times in the same printf() statement. This doesn't work if all values 'v' are unknown. I suggest we allow for max 4 buffer to be returned in a round-robin fashion. --- tcpdump-2004.03.24/util.c Mon Dec 29 12:07:17 2003 +++ util.c Wed Mar 24 20:22:23 2004 @@ -212,7 +212,9 @@ 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 @@ } 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 (const char*) ret; } --gv - This is the TCPDUMP workers list. It is archived at http://www.tcpdump.org/lists/workers/index.html To unsubscribe use mailto:tcpdump-workers-request () tcpdump org?body=unsubscribe
Current thread:
- tok2str() patch Gisle Vanem (Mar 24)