svn commit: r291090 - head/usr.bin/vmstat
John Baldwin
jhb at freebsd.org
Fri Nov 20 18:49:09 UTC 2015
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
More information about the svn-src-all
mailing list