From owner-p4-projects@FreeBSD.ORG Tue Apr 29 19:23:32 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id C7DDD1065677; Tue, 29 Apr 2008 19:23:32 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 87ADD1065672 for ; Tue, 29 Apr 2008 19:23:32 +0000 (UTC) (envelope-from sam@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 761B58FC19 for ; Tue, 29 Apr 2008 19:23:32 +0000 (UTC) (envelope-from sam@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m3TJNWTH020927 for ; Tue, 29 Apr 2008 19:23:32 GMT (envelope-from sam@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m3TJNWnr020925 for perforce@freebsd.org; Tue, 29 Apr 2008 19:23:32 GMT (envelope-from sam@freebsd.org) Date: Tue, 29 Apr 2008 19:23:32 GMT Message-Id: <200804291923.m3TJNWnr020925@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to sam@freebsd.org using -f From: Sam Leffler To: Perforce Change Reviews Cc: Subject: PERFORCE change 140880 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Apr 2008 19:23:33 -0000 http://perforce.freebsd.org/chv.cgi?CH=140880 Change 140880 by sam@sam_ebb on 2008/04/29 19:23:27 there are now >127 stat entries so need to introduce an indirect array of indices since the compiled format is encoded in an uint8_t as ix | 0x80 Affected files ... .. //depot/projects/vap/tools/tools/net80211/wlanstats/statfoo.c#4 edit .. //depot/projects/vap/tools/tools/net80211/wlanstats/statfoo.h#4 edit Differences ... ==== //depot/projects/vap/tools/tools/net80211/wlanstats/statfoo.c#4 (text+ko) ==== @@ -40,9 +40,9 @@ #define N(a) (sizeof(a)/sizeof(a[0])) char fmt[4096]; char *fp, *tok; - int i, j; + int i, j, field; - j = 0; + j = field = 0; strlcpy(fmt, fmt0, sizeof(fmt)); for (fp = fmt; (tok = strsep(&fp, ", ")) != NULL;) { for (i = 0; i < sf->nstats; i++) @@ -58,9 +58,15 @@ "stopped at %s\n", sf->name, tok); break; } + if (field > 127) { + fprintf(stderr, "%s: too many fields; " + "stopped at %s\n", sf->name, tok); + break; + } if (j != 0) sf->fmts[j++] = ' '; - sf->fmts[j++] = 0x80 | i; + sf->fmts[j++] = 0x80 | field; + sf->fields[field++] = i; } sf->fmts[j] = '\0'; #undef N @@ -92,7 +98,8 @@ for (cp = sf->fmts; *cp != '\0'; cp++) { if (*cp & 0x80) { - const struct fmt *f = &sf->stats[*cp &~ 0x80]; + int six = sf->fields[*cp &~ 0x80]; + const struct fmt *f = &sf->stats[six]; fprintf(fd, "%*s", f->width, f->label); } else putc(*cp, fd); @@ -108,8 +115,9 @@ for (cp = sf->fmts; *cp != '\0'; cp++) { if (*cp & 0x80) { - const struct fmt *f = &sf->stats[*cp &~ 0x80]; - if (sf->get_curstat(sf, *cp &~ 0x80, buf, sizeof(buf))) + int six = sf->fields[*cp &~ 0x80]; + const struct fmt *f = &sf->stats[six]; + if (sf->get_curstat(sf, six, buf, sizeof(buf))) fprintf(fd, "%*s", f->width, buf); } else putc(*cp, fd); @@ -125,8 +133,9 @@ for (cp = sf->fmts; *cp != '\0'; cp++) { if (*cp & 0x80) { - const struct fmt *f = &sf->stats[*cp &~ 0x80]; - if (sf->get_totstat(sf, *cp &~ 0x80, buf, sizeof(buf))) + int six = sf->fields[*cp &~ 0x80]; + const struct fmt *f = &sf->stats[six]; + if (sf->get_totstat(sf, six, buf, sizeof(buf))) fprintf(fd, "%*s", f->width, buf); } else putc(*cp, fd); ==== //depot/projects/vap/tools/tools/net80211/wlanstats/statfoo.h#4 (text+ko) ==== @@ -79,6 +79,7 @@ const char *name; /* statistics name, e.g. wlanstats */ const struct fmt *stats; /* statistics in class */ int nstats; /* number of stats */ + int fields[128]; /* index of field referenced in fmts */ unsigned char fmts[4096]; /* private: compiled stats to display */ STATFOO_DECL_METHODS(struct statfoo *);