Date: Fri, 20 Nov 2015 10:48:16 -0800 From: John Baldwin <jhb@freebsd.org> To: Craig Rodrigues <rodrigc@freebsd.org> Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r291090 - head/usr.bin/vmstat Message-ID: <3730527.lGHZa1OL20@ralph.baldwin.cx> In-Reply-To: <201511200515.tAK5FZT8037263@repo.freebsd.org> References: <201511200515.tAK5FZT8037263@repo.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Friday, November 20, 2015 05:15:35 AM Craig Rodrigues wrote: > Author: rodrigc > Date: Fri Nov 20 05:15:34 2015 > New Revision: 291090 > URL: https://svnweb.freebsd.org/changeset/base/291090 > > Log: > Convert vmstat to use libxo. > > This patch was based on this patch: > https://github.com/Juniper/libxo/blob/master/patches/vmstat.patch > > by Phil Shafer at Juniper Networks, but updated to the latest > vmstat code. > > Reviewed by: allanjude > Differential Revision: https://reviews.freebsd.org/D3935 > > ... > > Modified: head/usr.bin/vmstat/vmstat.c > ============================================================================== > --- head/usr.bin/vmstat/vmstat.c Fri Nov 20 03:24:04 2015 (r291089) > +++ head/usr.bin/vmstat/vmstat.c Fri Nov 20 05:15:34 2015 (r291090) > @@ -277,20 +288,34 @@ retry_nlist: > namelist[X_SUM].n_name = "_cnt"; > goto retry_nlist; > } > - warnx("undefined symbols:"); > for (c = 0; > c < (int)(sizeof(namelist)/sizeof(namelist[0])); > c++) > if (namelist[c].n_type == 0) > - (void)fprintf(stderr, " %s", > + bufsize += strlen(namelist[c].n_name) + 1; > + bufsize += len + 1; > + buf = bp = alloca(bufsize); > + > + for (c = 0; > + c < (int)(sizeof(namelist)/sizeof(namelist[0])); > + c++) > + if (namelist[c].n_type == 0) { > + xo_error(" %s", > namelist[c].n_name); > - (void)fputc('\n', stderr); > + len = strlen(namelist[c].n_name); > + *bp++ = ' '; > + memcpy(bp, namelist[c].n_name, len); > + bp += len; > + } > + *bp = '\0'; > + xo_error("undefined symbols:\n", buf); Please use some sort of string builder (sbuf or open_memstream()) instead of manual string assembly. The former is easier to read and the latter is more error-prone. Suggested replacement: FILE *fp; fp = open_memstream(&buf, &bufsize); for (c = 0; c < nitems(namelist); c++) { if (namelist[c].n_type == 0) { xo_error(" %s", namelist[c].n_name); (void)fprintf(fp, " %s", namelist[c].n_name); } } fclose(fp); xo_error("undefined symbols:\n", buf); free(buf); -- John Baldwin
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3730527.lGHZa1OL20>