diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2002-05-29 09:23:26 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2002-05-29 09:23:26 +0000 |
commit | 0a56e23187a30c4b263905e9efc35ed738183fd4 (patch) | |
tree | 741d64038c2ad586ad319e2208c44e223da70e0f /usr.bin | |
parent | a2f77e2c291ced0b85e36486c6ca1e2cfb53b64a (diff) |
more snprintf
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/cal/cal.c | 11 | ||||
-rw-r--r-- | usr.bin/chpass/pw_yp.c | 10 | ||||
-rw-r--r-- | usr.bin/make/util.c | 24 | ||||
-rw-r--r-- | usr.bin/nc/netcat.c | 4 | ||||
-rw-r--r-- | usr.bin/pctr/pctr.c | 13 | ||||
-rw-r--r-- | usr.bin/tip/uucplock.c | 10 | ||||
-rw-r--r-- | usr.bin/vmstat/vmstat.c | 6 |
7 files changed, 41 insertions, 37 deletions
diff --git a/usr.bin/cal/cal.c b/usr.bin/cal/cal.c index 470e1acebe7..e5aa391826d 100644 --- a/usr.bin/cal/cal.c +++ b/usr.bin/cal/cal.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cal.c,v 1.7 2002/02/16 21:27:44 millert Exp $ */ +/* $OpenBSD: cal.c,v 1.8 2002/05/29 09:23:25 deraadt Exp $ */ /* $NetBSD: cal.c,v 1.6 1995/03/26 03:10:24 glass Exp $ */ /* @@ -47,7 +47,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)cal.c 8.4 (Berkeley) 4/2/94"; #else -static char rcsid[] = "$OpenBSD: cal.c,v 1.7 2002/02/16 21:27:44 millert Exp $"; +static char rcsid[] = "$OpenBSD: cal.c,v 1.8 2002/05/29 09:23:25 deraadt Exp $"; #endif #endif /* not lint */ @@ -207,7 +207,8 @@ monthly(month, year) char *p, lineout[30]; day_array(month, year, days); - len = sprintf(lineout, "%s %d", month_names[month - 1], year); + len = snprintf(lineout, sizeof lineout, "%s %d", + month_names[month - 1], year); (void)printf("%*s%s\n%s\n", ((julian ? J_WEEK_LEN : WEEK_LEN) - len) / 2, "", lineout, julian ? j_day_headings : day_headings); @@ -229,7 +230,7 @@ j_yearly(year) int days[12][MAXDAYS]; char *p, lineout[80]; - (void)sprintf(lineout, "%d", year); + (void)snprintf(lineout, sizeof lineout, "%d", year); center(lineout, J_WEEK_LEN * 2 + J_HEAD_SEP, 0); (void)printf("\n\n"); for (i = 0; i < 12; i++) @@ -264,7 +265,7 @@ yearly(year) int days[12][MAXDAYS]; char *p, lineout[80]; - (void)sprintf(lineout, "%d", year); + (void)snprintf(lineout, sizeof lineout, "%d", year); center(lineout, WEEK_LEN * 3 + HEAD_SEP * 2, 0); (void)printf("\n\n"); for (i = 0; i < 12; i++) diff --git a/usr.bin/chpass/pw_yp.c b/usr.bin/chpass/pw_yp.c index 75f775b218d..cbf75b23baa 100644 --- a/usr.bin/chpass/pw_yp.c +++ b/usr.bin/chpass/pw_yp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pw_yp.c,v 1.13 2001/11/19 19:02:13 mpech Exp $ */ +/* $OpenBSD: pw_yp.c,v 1.14 2002/05/29 09:23:25 deraadt Exp $ */ /* $NetBSD: pw_yp.c,v 1.5 1995/03/26 04:55:33 glass Exp $ */ /* @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)pw_yp.c 1.0 2/2/93"; #else -static char rcsid[] = "$OpenBSD: pw_yp.c,v 1.13 2001/11/19 19:02:13 mpech Exp $"; +static char rcsid[] = "$OpenBSD: pw_yp.c,v 1.14 2002/05/29 09:23:25 deraadt Exp $"; #endif #endif /* not lint */ @@ -131,8 +131,8 @@ pw_yp(pw, uid) if (*p == '&') alen = alen + strlen(pw->pw_name) - 1; if (strlen(pw->pw_name) + 1 + strlen(pw->pw_passwd) + 1 + - strlen((sprintf(buf, "%u", pw->pw_uid), buf)) + 1 + - strlen((sprintf(buf, "%u", pw->pw_gid), buf)) + 1 + + strlen((snprintf(buf, sizeof buf, "%u", pw->pw_uid), buf)) + 1 + + strlen((snprintf(buf, sizeof buf, "%u", pw->pw_gid), buf)) + 1 + strlen(pw->pw_gecos) + alen + 1 + strlen(pw->pw_dir) + 1 + strlen(pw->pw_shell) >= 1023) { warnx("entries too long"); @@ -280,7 +280,7 @@ ypgetpwuid(uid) exit(1); } - sprintf(namebuf, "%u", uid); + snprintf(namebuf, sizeof namebuf, "%u", uid); reason = yp_match(domain, "passwd.byuid", namebuf, strlen(namebuf), &val, &vallen); switch(reason) { diff --git a/usr.bin/make/util.c b/usr.bin/make/util.c index 131bd9e18c0..0a82f579b5a 100644 --- a/usr.bin/make/util.c +++ b/usr.bin/make/util.c @@ -1,5 +1,5 @@ /* $OpenPackages$ */ -/* $OpenBSD: util.c,v 1.17 2002/02/19 19:39:38 millert Exp $ */ +/* $OpenBSD: util.c,v 1.18 2002/05/29 09:23:25 deraadt Exp $ */ /* $NetBSD: util.c,v 1.10 1996/12/31 17:56:04 christos Exp $ */ /* @@ -46,7 +46,7 @@ strerror(e) { static char buf[100]; if (e < 0 || e >= sys_nerr) { - sprintf(buf, "Unknown error %d", e); + snprintf(buf, sizeof buf, "Unknown error %d", e); return buf; } else @@ -208,7 +208,7 @@ getwd(pathname) /* find the inode of root */ if (stat("/", &st_root) == -1) { (void)sprintf(pathname, - "getwd: Cannot stat \"/\" (%s)", strerror(errno)); + "getwd: Cannot stat \"/\" (%s)", strerror(errno)); return NULL; } pathbuf[MAXPATHLEN - 1] = '\0'; @@ -219,7 +219,7 @@ getwd(pathname) /* find the inode of the current directory */ if (lstat(".", &st_cur) == -1) { (void)sprintf(pathname, - "getwd: Cannot stat \".\" (%s)", strerror(errno)); + "getwd: Cannot stat \".\" (%s)", strerror(errno)); return NULL; } nextpathptr = strrcpy(nextpathptr, "../"); @@ -237,14 +237,14 @@ getwd(pathname) /* open the parent directory */ if (stat(nextpathptr, &st_dotdot) == -1) { (void)sprintf(pathname, - "getwd: Cannot stat directory \"%s\" (%s)", - nextpathptr, strerror(errno)); + "getwd: Cannot stat directory \"%s\" (%s)", + nextpathptr, strerror(errno)); return NULL; } if ((dp = opendir(nextpathptr)) == NULL) { (void)sprintf(pathname, - "getwd: Cannot open directory \"%s\" (%s)", - nextpathptr, strerror(errno)); + "getwd: Cannot open directory \"%s\" (%s)", + nextpathptr, strerror(errno)); return NULL; } @@ -265,8 +265,9 @@ getwd(pathname) continue; (void)strcpy(cur_name_add, d->d_name); if (lstat(nextpathptr, &st_next) == -1) { - (void)sprintf(pathname, "getwd: Cannot stat \"%s\" (%s)", - d->d_name, strerror(errno)); + (void)sprintf(pathname, + "getwd: Cannot stat \"%s\" (%s)", + d->d_name, strerror(errno)); (void)closedir(dp); return NULL; } @@ -277,7 +278,8 @@ getwd(pathname) } } if (d == NULL) { - (void)sprintf(pathname, "getwd: Cannot find \".\" in \"..\""); + (void)sprintf(pathname, + "getwd: Cannot find \".\" in \"..\""); (void)closedir(dp); return NULL; } diff --git a/usr.bin/nc/netcat.c b/usr.bin/nc/netcat.c index da57c3239ac..3a1e9c11937 100644 --- a/usr.bin/nc/netcat.c +++ b/usr.bin/nc/netcat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: netcat.c,v 1.47 2002/03/10 20:26:09 ericj Exp $ */ +/* $OpenBSD: netcat.c,v 1.48 2002/05/29 09:23:25 deraadt Exp $ */ /* * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> * @@ -645,7 +645,7 @@ build_ports(char *p) /* Load ports sequentially */ for (cp = lo; cp <= hi; cp++) { portlist[x] = calloc(1, PORT_MAX); - sprintf(portlist[x], "%d", cp); + snprintf(portlist[x], PORT_MAX, "%d", cp); x++; } diff --git a/usr.bin/pctr/pctr.c b/usr.bin/pctr/pctr.c index 4a85a6cf6e9..c297f2c6e1c 100644 --- a/usr.bin/pctr/pctr.c +++ b/usr.bin/pctr/pctr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pctr.c,v 1.7 2001/08/19 19:26:03 mickey Exp $ */ +/* $OpenBSD: pctr.c,v 1.8 2002/05/29 09:23:25 deraadt Exp $ */ /* * Pentium performance counter control program for OpenBSD. @@ -327,7 +327,7 @@ fn2str (int family, u_int sel) if (family == 5) { fn = sel & 0x3f; cfnp = fn2cfnp (family, fn); - sprintf(buf, "%c%c%c %02x %s", + snprintf(buf, sizeof buf, "%c%c%c %02x %s", sel & P5CTR_C ? 'c' : '-', sel & P5CTR_U ? 'u' : '-', sel & P5CTR_K ? 'k' : '-', @@ -337,16 +337,17 @@ fn2str (int family, u_int sel) fn = sel & 0xff; cfnp = fn2cfnp (family, fn); if (cfnp && cfnp->flags & CFL_MESI) - sprintf(um, "/%c%c%c%c", + snprintf(um, sizeof um, "/%c%c%c%c", sel & P6CTR_UM_M ? 'm' : '-', sel & P6CTR_UM_E ? 'e' : '-', sel & P6CTR_UM_S ? 's' : '-', sel & P6CTR_UM_I ? 'i' : '-'); else if (cfnp && cfnp->flags & CFL_SA) - sprintf(um, "/%c", sel & P6CTR_UM_A ? 'a' : '-'); + snprintf(um, sizeof um, "/%c", + sel & P6CTR_UM_A ? 'a' : '-'); if (sel >> 24) - sprintf(cm, "+%d", sel >> 24); - sprintf(buf, "%c%c%c%c %02x%s%s%*s %s", + snprintf(cm, sizeof cm, "+%d", sel >> 24); + snprintf(buf, sizeof buf, "%c%c%c%c %02x%s%s%*s %s", sel & P6CTR_I ? 'i' : '-', sel & P6CTR_E ? 'e' : '-', sel & P6CTR_K ? 'k' : '-', diff --git a/usr.bin/tip/uucplock.c b/usr.bin/tip/uucplock.c index 406bde54a62..8c32fd91de7 100644 --- a/usr.bin/tip/uucplock.c +++ b/usr.bin/tip/uucplock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uucplock.c,v 1.7 2002/05/07 06:56:50 hugh Exp $ */ +/* $OpenBSD: uucplock.c,v 1.8 2002/05/29 09:23:25 deraadt Exp $ */ /* $NetBSD: uucplock.c,v 1.7 1997/02/11 09:24:08 mrg Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)uucplock.c 8.1 (Berkeley) 6/6/93"; #endif -static const char rcsid[] = "$OpenBSD: uucplock.c,v 1.7 2002/05/07 06:56:50 hugh Exp $"; +static const char rcsid[] = "$OpenBSD: uucplock.c,v 1.8 2002/05/29 09:23:25 deraadt Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -62,10 +62,10 @@ int uu_lock(ttyname) char *ttyname; { - int fd, pid; + int fd, len; char tbuf[sizeof(_PATH_LOCKDIRNAME) + MAXNAMLEN]; char text_pid[81]; - int len; + pid_t pid; (void)snprintf(tbuf, sizeof tbuf, _PATH_LOCKDIRNAME, ttyname); fd = open(tbuf, O_RDWR|O_CREAT|O_EXCL, 0660); @@ -109,7 +109,7 @@ uu_lock(ttyname) /* fall out and finish the locking process */ } pid = getpid(); - (void)sprintf(text_pid, "%10d\n", pid); + (void)snprintf(text_pid, sizeof text_pid, "%10ld\n", (long)pid); len = strlen(text_pid); if (write(fd, text_pid, len) != len) { (void)close(fd); diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c index 90a9d67c26b..91e419fc837 100644 --- a/usr.bin/vmstat/vmstat.c +++ b/usr.bin/vmstat/vmstat.c @@ -1,5 +1,5 @@ /* $NetBSD: vmstat.c,v 1.29.4.1 1996/06/05 00:21:05 cgd Exp $ */ -/* $OpenBSD: vmstat.c,v 1.68 2002/03/15 19:11:01 art Exp $ */ +/* $OpenBSD: vmstat.c,v 1.69 2002/05/29 09:23:25 deraadt Exp $ */ /* * Copyright (c) 1980, 1986, 1991, 1993 @@ -1076,9 +1076,9 @@ print_pool(struct pool *pp, char *name) return; if (pp->pr_maxpages == UINT_MAX) - sprintf(maxp, "inf"); + snprintf(maxp, sizeof maxp, "inf"); else - sprintf(maxp, "%u", pp->pr_maxpages); + snprintf(maxp, sizeof maxp, "%u", pp->pr_maxpages); /* * Print single word. `ovflow' is number of characters didn't fit * on the last word. `fmt' is a format string to print this word. |