Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch simplify snprintf.
details: https://anonhg.NetBSD.org/src/rev/d316f1616038
branches: trunk
changeset: 794839:d316f1616038
user: christos <christos%NetBSD.org@localhost>
date: Wed Mar 26 15:55:31 2014 +0000
description:
simplify snprintf.
diffstat:
sys/arch/sparc/sparc/autoconf.c | 31 ++++++++++++++++---------------
sys/arch/sparc64/sparc64/autoconf.c | 8 +++-----
2 files changed, 19 insertions(+), 20 deletions(-)
diffs (134 lines):
diff -r b599a8bba619 -r d316f1616038 sys/arch/sparc/sparc/autoconf.c
--- a/sys/arch/sparc/sparc/autoconf.c Wed Mar 26 15:47:00 2014 +0000
+++ b/sys/arch/sparc/sparc/autoconf.c Wed Mar 26 15:55:31 2014 +0000
@@ -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 @@
} 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 @@
*/
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 @@
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 @@
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 @@
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 @@
* 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;
diff -r b599a8bba619 -r d316f1616038 sys/arch/sparc64/sparc64/autoconf.c
--- a/sys/arch/sparc64/sparc64/autoconf.c Wed Mar 26 15:47:00 2014 +0000
+++ b/sys/arch/sparc64/sparc64/autoconf.c Wed Mar 26 15:55:31 2014 +0000
@@ -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 @@
char *
clockfreq(long freq)
{
- char *p;
static char sbuf[10];
size_t len;
@@ -519,8 +518,7 @@
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);
}
Home |
Main Index |
Thread Index |
Old Index