use bounded string op

This commit is contained in:
itojun 2003-07-13 12:29:20 +00:00
parent d0a2aaaa79
commit e8f0e61fd7
9 changed files with 51 additions and 46 deletions

View File

@ -1,5 +1,5 @@
%{
/* $NetBSD: gram.y,v 1.41 2003/01/27 05:00:54 thorpej Exp $ */
/* $NetBSD: gram.y,v 1.42 2003/07/13 12:36:48 itojun Exp $ */
/*
* Copyright (c) 1992, 1993
@ -592,7 +592,7 @@ setmachine(const char *mch, const char *mcharch, struct nvlist *mchsubarches)
* Set up the file inclusion stack. This empty include tells
* the parser there are no more device definitions coming.
*/
strcpy(buf, _PATH_DEVNULL);
strlcpy(buf, _PATH_DEVNULL, sizeof(buf));
if (include(buf, ENDDEFS, 0, 0) != 0)
exit(1);
@ -614,7 +614,7 @@ setmachine(const char *mch, const char *mcharch, struct nvlist *mchsubarches)
(void)sprintf(buf, "arch/%s/conf/files.%s",
machinearch, machinearch);
else
strcpy(buf, _PATH_DEVNULL);
strlcpy(buf, _PATH_DEVNULL, sizeof(buf));
if (include(buf, ENDFILE, 0, 0) != 0)
exit(1);

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.81 2003/07/02 16:47:53 jrf Exp $ */
/* $NetBSD: main.c,v 1.82 2003/07/13 12:36:48 itojun Exp $ */
/*
* Copyright (c) 1992, 1993
@ -269,7 +269,7 @@ main(int argc, char **argv)
last_component = strrchr(conffile, '/');
last_component = (last_component) ? last_component + 1 : conffile;
if (pflag) {
p = emalloc(strlen(last_component) + 17);
p = emalloc(strlen(last_component) + 17);
(void)sprintf(p, "../compile/%s.PROF", last_component);
(void)addmkoption(intern("PROF"), "-pg");
(void)addoption(intern("GPROF"), NULL);
@ -462,7 +462,7 @@ mksymlinks(void)
const char *q;
struct nvlist *nv;
sprintf(buf, "arch/%s/include", machine);
snprintf(buf, sizeof(buf), "arch/%s/include", machine);
p = sourcepath(buf);
ret = unlink("machine");
if (ret && errno != ENOENT)
@ -475,7 +475,7 @@ mksymlinks(void)
free(p);
if (machinearch != NULL) {
sprintf(buf, "arch/%s/include", machinearch);
snprintf(buf, sizeof(buf), "arch/%s/include", machinearch);
p = sourcepath(buf);
q = machinearch;
} else {
@ -494,7 +494,7 @@ mksymlinks(void)
for (nv = machinesubarches; nv != NULL; nv = nv->nv_next) {
q = nv->nv_name;
sprintf(buf, "arch/%s/include", q);
snprintf(buf, sizeof(buf), "arch/%s/include", q);
p = sourcepath(buf);
ret = unlink(q);
if (ret && errno != ENOENT)
@ -656,12 +656,12 @@ defopt(struct hashtab *ht, const char *fname, struct nvlist *opts,
* lower case name will be used as the option
* file name.
*/
(void) strcpy(low, "opt_");
(void) strlcpy(low, "opt_", sizeof(low));
p = low + strlen(low);
for (n = nv->nv_name; (c = *n) != '\0'; n++)
*p++ = isupper(c) ? tolower(c) : c;
*p = '\0';
strcat(low, ".h");
strlcat(low, ".h", sizeof(low));
name = intern(low);
} else {

View File

@ -1,4 +1,4 @@
/* $NetBSD: mkheaders.c,v 1.33 2002/11/19 04:29:19 atatat Exp $ */
/* $NetBSD: mkheaders.c,v 1.34 2003/07/13 12:36:48 itojun Exp $ */
/*
* Copyright (c) 1992, 1993
@ -105,8 +105,8 @@ emitcnt(struct nvlist *head)
struct nvlist *nv;
FILE *fp;
(void)sprintf(nfname, "%s.h", head->nv_name);
(void)sprintf(tfname, "tmp_%s", nfname);
(void)snprintf(nfname, sizeof(nfname), "%s.h", head->nv_name);
(void)snprintf(tfname, sizeof(tfname), "tmp_%s", nfname);
if ((fp = fopen(tfname, "w")) == NULL)
return (herr("open", tfname, NULL));
@ -163,7 +163,7 @@ defopts_print(const char *name, void *value, void *arg)
int isfsoption;
FILE *fp;
(void)sprintf(tfname, "tmp_%s", name);
(void)snprintf(tfname, sizeof(tfname), "tmp_%s", name);
if ((fp = fopen(tfname, "w")) == NULL)
return (herr("open", tfname, NULL));

View File

@ -1,4 +1,4 @@
/* $NetBSD: mkmakefile.c,v 1.57 2002/11/19 04:24:16 atatat Exp $ */
/* $NetBSD: mkmakefile.c,v 1.58 2003/07/13 12:36:49 itojun Exp $ */
/*
* Copyright (c) 1992, 1993
@ -82,13 +82,14 @@ mkmakefile(void)
/* Try a makefile for the port first.
*/
(void)sprintf(buf, "arch/%s/conf/Makefile.%s", machine, machine);
(void)snprintf(buf, sizeof(buf), "arch/%s/conf/Makefile.%s",
machine, machine);
ifname = sourcepath(buf);
if ((ifp = fopen(ifname, "r")) == NULL) {
/* Try a makefile for the architecture second.
*/
(void)sprintf(buf, "arch/%s/conf/Makefile.%s", machinearch,
machinearch);
(void)snprintf(buf, sizeof(buf), "arch/%s/conf/Makefile.%s",
machinearch, machinearch);
ifname = sourcepath(buf);
}
if ((ifp = fopen(ifname, "r")) == NULL) {
@ -382,7 +383,8 @@ emitfiles(FILE *fp, int suffix, int upper_suffix)
*/
if (suffix == 'c') {
TAILQ_FOREACH(cf, &allcf, cf_next) {
(void)sprintf(swapname, "swap%s.c", cf->cf_name);
(void)snprintf(swapname, sizeof(swapname), "swap%s.c",
cf->cf_name);
len = strlen(swapname);
if (lpos + len > 72) {
if (fputs(" \\\n", fp) < 0)
@ -437,7 +439,7 @@ emitrules(FILE *fp)
ch = fpath[strlen(fpath) - 1];
if (islower(ch))
ch = toupper(ch);
(void)sprintf(buf, "${%s_%c}", cp, ch);
(void)snprintf(buf, sizeof(buf), "${%s_%c}", cp, ch);
cp = buf;
}
if (fprintf(fp, "\t%s\n\n", cp) < 0)

View File

@ -1,4 +1,4 @@
/* $NetBSD: mkswap.c,v 1.14 2002/06/05 10:56:19 lukem Exp $ */
/* $NetBSD: mkswap.c,v 1.15 2003/07/13 12:36:49 itojun Exp $ */
/*
* Copyright (c) 1992, 1993
@ -76,9 +76,10 @@ mkdevstr(dev_t d)
static char buf[32];
if (d == NODEV)
(void)sprintf(buf, "NODEV");
(void)snprintf(buf, sizeof(buf), "NODEV");
else
(void)sprintf(buf, "makedev(%d, %d)", major(d), minor(d));
(void)snprintf(buf, sizeof(buf), "makedev(%d, %d)",
major(d), minor(d));
return buf;
}
@ -90,8 +91,8 @@ mkoneswap(struct config *cf)
char fname[200], tname[200];
char specinfo[200];
(void)sprintf(fname, "swap%s.c", cf->cf_name);
(void)sprintf(tname, "swap%s.c.tmp", cf->cf_name);
(void)snprintf(fname, sizeof(fname), "swap%s.c", cf->cf_name);
(void)snprintf(tname, sizeof(tname), "swap%s.c.tmp", cf->cf_name);
if ((fp = fopen(tname, "w")) == NULL) {
(void)fprintf(stderr, "config: cannot write %s: %s\n",
fname, strerror(errno));
@ -107,9 +108,10 @@ mkoneswap(struct config *cf)
*/
nv = cf->cf_root;
if (cf->cf_root->nv_str == s_qmark)
strcpy(specinfo, "NULL");
strlcpy(specinfo, "NULL", sizeof(specinfo));
else
sprintf(specinfo, "\"%s\"", cf->cf_root->nv_str);
snprintf(specinfo, sizeof(specinfo), "\"%s\"",
cf->cf_root->nv_str);
if (fprintf(fp, "const char *rootspec = %s;\n", specinfo) < 0)
goto wrerror;
if (fprintf(fp, "dev_t\trootdev = %s;\t/* %s */\n\n",
@ -122,9 +124,9 @@ mkoneswap(struct config *cf)
*/
nv = cf->cf_dump;
if (cf->cf_dump == NULL)
strcpy(specinfo, "NULL");
strlcpy(specinfo, "NULL", sizeof(specinfo));
else
sprintf(specinfo, "\"%s\"", cf->cf_dump->nv_str);
snprintf(specinfo, sizeof(specinfo), "\"%s\"", cf->cf_dump->nv_str);
if (fprintf(fp, "const char *dumpspec = %s;\n", specinfo) < 0)
goto wrerror;
if (fprintf(fp, "dev_t\tdumpdev = %s;\t/* %s */\n\n",
@ -136,9 +138,10 @@ mkoneswap(struct config *cf)
* Emit the root file system.
*/
if (cf->cf_fstype == NULL)
strcpy(specinfo, "NULL");
strlcpy(specinfo, "NULL", sizeof(specinfo));
else {
sprintf(specinfo, "%s_mountroot", cf->cf_fstype);
snprintf(specinfo, sizeof(specinfo), "%s_mountroot",
cf->cf_fstype);
if (fprintf(fp, "int %s(void);\n", specinfo) < 0)
goto wrerror;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: sem.c,v 1.37 2003/01/27 05:00:55 thorpej Exp $ */
/* $NetBSD: sem.c,v 1.38 2003/07/13 12:36:49 itojun Exp $ */
/*
* Copyright (c) 1992, 1993
@ -656,9 +656,9 @@ makedevstr(int maj, int min)
devname = major2name(maj);
if (devname == NULL)
(void)sprintf(buf, "<%d/%d>", maj, min);
(void)snprintf(buf, sizeof(buf), "<%d/%d>", maj, min);
else
(void)sprintf(buf, "%s%d%c", devname,
(void)snprintf(buf, sizeof(buf), "%s%d%c", devname,
min / maxpartitions, (min % maxpartitions) + 'a');
return (intern(buf));

View File

@ -1,4 +1,4 @@
/* $NetBSD: strerror.c,v 1.3 2000/10/02 19:48:35 cgd Exp $ */
/* $NetBSD: strerror.c,v 1.4 2003/07/13 12:36:49 itojun Exp $ */
/*
* strerror() - for those systems that don't have it yet.
@ -14,9 +14,9 @@ char *
strerror(int en)
{
if ((0 <= en) && (en < sys_nerr))
return sys_errlist[en];
if ((0 <= en) && (en < sys_nerr))
return sys_errlist[en];
sprintf(errmsg, "Error %d", en);
return errmsg;
snprintf(errmsg, sizeof(errmsg), "Error %d", en);
return errmsg;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: cmds.c,v 1.6 2002/08/26 17:04:17 ad Exp $ */
/* $NetBSD: cmds.c,v 1.7 2003/07/13 12:30:17 itojun Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -66,7 +66,7 @@
#ifndef lint
#include <sys/cdefs.h>
__RCSID("$NetBSD: cmds.c,v 1.6 2002/08/26 17:04:17 ad Exp $");
__RCSID("$NetBSD: cmds.c,v 1.7 2003/07/13 12:30:17 itojun Exp $");
#endif /* not lint */
#include <sys/types.h>
@ -202,7 +202,7 @@ cmd_cstatus(char **argv)
}
if (i == sizeof(mlx_ctlr_names) / sizeof(mlx_ctlr_names[0])) {
sprintf(buf, " model 0x%x", ci.ci_hardware_id);
snprintf(buf, sizeof(buf), " model 0x%x", ci.ci_hardware_id);
model = buf;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: rarpd.c,v 1.48 2003/05/15 14:50:02 itojun Exp $ */
/* $NetBSD: rarpd.c,v 1.49 2003/07/13 12:29:20 itojun Exp $ */
/*
* Copyright (c) 1990 The Regents of the University of California.
@ -28,7 +28,7 @@ __COPYRIGHT(
#endif /* not lint */
#ifndef lint
__RCSID("$NetBSD: rarpd.c,v 1.48 2003/05/15 14:50:02 itojun Exp $");
__RCSID("$NetBSD: rarpd.c,v 1.49 2003/07/13 12:29:20 itojun Exp $");
#endif
@ -283,7 +283,7 @@ bpf_open(void)
/* Go through all the minors and find one that isn't in use. */
do {
(void)sprintf(device, "/dev/bpf%d", n++);
(void)snprintf(device, sizeof(device), "/dev/bpf%d", n++);
fd = open(device, O_RDWR);
} while (fd < 0 && errno == EBUSY);
@ -527,7 +527,7 @@ rarp_bootable(u_int32_t addr)
char ipname[9];
static DIR *dd = 0;
(void)sprintf(ipname, "%08X", addr);
(void)snprintf(ipname, sizeof(ipname), "%08X", addr);
/* If directory is already open, rewind it. Otherwise, open it. */
if (d = dd)
rewinddir(d);