Module Name: src
Committed By: christos
Date: Wed Mar 26 15:55:31 UTC 2014
Modified Files:
src/sys/arch/sparc/sparc: autoconf.c
src/sys/arch/sparc64/sparc64: autoconf.c
Log Message:
simplify snprintf.
To generate a diff of this commit:
cvs rdiff -u -r1.251 -r1.252 src/sys/arch/sparc/sparc/autoconf.c
cvs rdiff -u -r1.194 -r1.195 src/sys/arch/sparc64/sparc64/autoconf.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/sparc/sparc/autoconf.c
diff -u src/sys/arch/sparc/sparc/autoconf.c:1.251 src/sys/arch/sparc/sparc/autoconf.c:1.252
--- src/sys/arch/sparc/sparc/autoconf.c:1.251 Tue Apr 16 02:57:06 2013
+++ src/sys/arch/sparc/sparc/autoconf.c Wed Mar 26 11:55:31 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: autoconf.c,v 1.251 2013/04/16 06:57:06 jdc Exp $ */
+/* $NetBSD: autoconf.c,v 1.252 2014/03/26 15:55:31 christos Exp $ */
/*
* Copyright (c) 1996
@@ -48,7 +48,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.251 2013/04/16 06:57:06 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.252 2014/03/26 15:55:31 christos Exp $");
#include "opt_ddb.h"
#include "opt_kgdb.h"
@@ -673,9 +673,11 @@ bootpath_fake(struct bootpath *bp, const
} else {
BP_APPEND(bp, "vme", -1, 0, 0);
}
- sprintf(tmpname,"x%cc", cp[1]); /* e.g. `xdc' */
+ /* e.g. `xdc' */
+ snprintf(tmpname, sizeof(tmpname), "x%cc", cp[1]);
BP_APPEND(bp, tmpname, -1, v0val[0], 0);
- sprintf(tmpname,"x%c", cp[1]); /* e.g. `xd' */
+ /* e.g. `xd' */
+ snprintf(tmpname, sizeof(tmpname), "x%c", cp[1]);
BP_APPEND(bp, tmpname, v0val[1], v0val[2], 0);
return;
}
@@ -686,7 +688,7 @@ bootpath_fake(struct bootpath *bp, const
*/
if ((cp[0] == 'i' || cp[0] == 'l') && cp[1] == 'e') {
BP_APPEND(bp, "obio", -1, 0, 0);
- sprintf(tmpname,"%c%c", cp[0], cp[1]);
+ snprintf(tmpname, sizeof(tmpname), "%c%c", cp[0], cp[1]);
BP_APPEND(bp, tmpname, -1, 0, 0);
return;
}
@@ -735,7 +737,8 @@ bootpath_fake(struct bootpath *bp, const
target = v0val[1] >> 2; /* old format */
lun = v0val[1] & 0x3;
}
- sprintf(tmpname, "%c%c", cp[0], cp[1]);
+ snprintf(tmpname, sizeof(tmpname),
+ "%c%c", cp[0], cp[1]);
BP_APPEND(bp, tmpname, target, lun, v0val[2]);
return;
}
@@ -786,9 +789,9 @@ bootpath_fake(struct bootpath *bp, const
BP_APPEND(bp, "sbus", -1, 0, 0);
BP_APPEND(bp, "esp", -1, v0val[0], 0);
if (cp[1] == 'r')
- sprintf(tmpname, "cd"); /* netbsd uses 'cd', not 'sr'*/
+ snprintf(tmpname, sizeof(tmpname), "cd"); /* netbsd uses 'cd', not 'sr'*/
else
- sprintf(tmpname,"%c%c", cp[0], cp[1]);
+ snprintf(tmpname, sizeof(tmpname), "%c%c", cp[0], cp[1]);
/* XXX - is TARGET/LUN encoded in v0val[1]? */
target = v0val[1];
lun = 0;
@@ -1030,17 +1033,15 @@ sync_crash(void)
char *
clockfreq(int freq)
{
- char *p;
static char buf[10];
+ size_t len;
freq /= 1000;
- sprintf(buf, "%d", freq / 1000);
+ len = snprintf(buf, sizeof(buf), "%d", freq / 1000);
freq %= 1000;
if (freq) {
freq += 1000; /* now in 1000..1999 */
- p = buf + strlen(buf);
- sprintf(p, "%d", freq);
- *p = '.'; /* now buf = %d.%3d */
+ snprintf(buf + len, sizeof(buf) - len, ".%d", freq);
}
return (buf);
}
@@ -1482,11 +1483,11 @@ romgetcursoraddr(int **rowp, int **colp)
* correct cutoff point is unknown, as yet; we use 2.9 here.
*/
if (prom_version() < 2 || prom_revision() < 0x00020009)
- sprintf(buf,
+ snprintf(buf, sizeof(buf),
"' line# >body >user %lx ! ' column# >body >user %lx !",
(u_long)rowp, (u_long)colp);
else
- sprintf(buf,
+ snprintf(buf, sizeof(buf),
"stdout @ is my-self addr line# %lx ! addr column# %lx !",
(u_long)rowp, (u_long)colp);
*rowp = *colp = NULL;
Index: src/sys/arch/sparc64/sparc64/autoconf.c
diff -u src/sys/arch/sparc64/sparc64/autoconf.c:1.194 src/sys/arch/sparc64/sparc64/autoconf.c:1.195
--- src/sys/arch/sparc64/sparc64/autoconf.c:1.194 Wed Mar 26 04:40:58 2014
+++ src/sys/arch/sparc64/sparc64/autoconf.c Wed Mar 26 11:55:31 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: autoconf.c,v 1.194 2014/03/26 08:40:58 christos Exp $ */
+/* $NetBSD: autoconf.c,v 1.195 2014/03/26 15:55:31 christos Exp $ */
/*
* Copyright (c) 1996
@@ -48,7 +48,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.194 2014/03/26 08:40:58 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.195 2014/03/26 15:55:31 christos Exp $");
#include "opt_ddb.h"
#include "opt_kgdb.h"
@@ -510,7 +510,6 @@ cpu_rootconf(void)
char *
clockfreq(long freq)
{
- char *p;
static char sbuf[10];
size_t len;
@@ -519,8 +518,7 @@ clockfreq(long freq)
freq %= 1000;
if (freq) {
freq += 1000; /* now in 1000..1999 */
- snprintf(sbuf + len, sizeof(sbuf) - len, "%ld", freq);
- *p = '.'; /* now sbuf = %d.%3d */
+ snprintf(sbuf + len, sizeof(sbuf) - len, ".%ld", freq);
}
return (sbuf);
}