Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/ia64 kill sprintf
details: https://anonhg.NetBSD.org/src/rev/51f165f97517
branches: trunk
changeset: 328079:51f165f97517
user: christos <christos%NetBSD.org@localhost>
date: Tue Mar 25 18:35:32 2014 +0000
description:
kill sprintf
diffstat:
sys/arch/ia64/disasm/disasm_format.c | 77 +++++++++++++++-------------
sys/arch/ia64/stand/common/boot.c | 19 +++---
sys/arch/ia64/stand/common/bootstrap.h | 8 +-
sys/arch/ia64/stand/common/commands.c | 52 ++++++++++++------
sys/arch/ia64/stand/common/dev_net.c | 4 +-
sys/arch/ia64/stand/common/fileload.c | 14 ++--
sys/arch/ia64/stand/common/interp.c | 16 +++---
sys/arch/ia64/stand/common/ls.c | 21 ++++---
sys/arch/ia64/stand/common/misc.c | 4 +-
sys/arch/ia64/stand/efi/libefi/devicename.c | 17 +++---
sys/arch/ia64/stand/efi/libefi/efifs.c | 4 +-
sys/arch/ia64/stand/ia64/efi/main.c | 8 +-
sys/arch/ia64/stand/ia64/ski/devicename.c | 15 ++---
13 files changed, 143 insertions(+), 116 deletions(-)
diffs (truncated from 813 to 300 lines):
diff -r e68622ff706c -r 51f165f97517 sys/arch/ia64/disasm/disasm_format.c
--- a/sys/arch/ia64/disasm/disasm_format.c Tue Mar 25 17:30:14 2014 +0000
+++ b/sys/arch/ia64/disasm/disasm_format.c Tue Mar 25 18:35:32 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: disasm_format.c,v 1.1 2006/04/07 14:21:18 cherry Exp $ */
+/* $NetBSD: disasm_format.c,v 1.2 2014/03/25 18:35:32 christos Exp $ */
/*-
* Copyright (c) 2000-2003 Marcel Moolenaar
@@ -111,21 +111,23 @@
};
void
-asm_completer(const struct asm_cmpltr *c, char *buf)
+asm_completer(const struct asm_cmpltr *c, char *buf, size_t buflen)
{
- strcpy(buf, asm_completers[c->c_type]);
+ strlcpy(buf, asm_completers[c->c_type], buflen);
}
void
-asm_mnemonic(enum asm_op op, char *buf)
+asm_mnemonic(enum asm_op op, char *buf, size_t buflen)
{
- strcpy(buf, asm_mnemonics[(op < ASM_OP_INTERNAL_OPCODES) ? op : 0]);
+ strlcpy(buf, asm_mnemonics[(op < ASM_OP_INTERNAL_OPCODES) ? op : 0],
+ buflen);
}
void
-asm_operand(const struct asm_oper *o, char *buf, uint64_t ip)
+asm_operand(const struct asm_oper *o, char *buf, size_t buflen, uint64_t ip)
{
const char *n;
+ size_t l;
n = "";
switch (o->o_type) {
@@ -159,16 +161,16 @@
case AR_LC: n = "lc"; break;
case AR_EC: n = "ec"; break;
default:
- sprintf(buf, "ar%d", (int)o->o_value);
+ snprintf(buf, buflen, "ar%d", (int)o->o_value);
return;
}
- sprintf(buf, "ar.%s", n);
+ snprintf(buf, buflen, "ar.%s", n);
return;
case ASM_OPER_BREG:
if (o->o_value != 0)
- sprintf(buf, "b%d", (int)o->o_value);
+ snprintf(buf, buflen, "b%d", (int)o->o_value);
else
- strcpy(buf, "rp");
+ strlcpy(buf, "rp", buflen);
return;
case ASM_OPER_CPUID:
n = "cpuid";
@@ -202,22 +204,22 @@
case CR_LRR0: n = "lrr0"; break;
case CR_LRR1: n = "lrr1"; break;
default:
- sprintf(buf, "cr%d", (int)o->o_value);
+ snprintf(buf, buflen, "cr%d", (int)o->o_value);
return;
}
- sprintf(buf, "cr.%s", n);
+ snprintf(buf, buflen, "cr.%s", n);
return;
case ASM_OPER_DBR:
n = "dbr";
break;
case ASM_OPER_DISP:
- sprintf(buf, "%lx", ip + o->o_value);
+ snprintf(buf, buflen, "%lx", ip + o->o_value);
return;
case ASM_OPER_DTR:
n = "dtr";
break;
case ASM_OPER_FREG:
- sprintf(buf, "f%d", (int)o->o_value);
+ snprintf(buf, buflen, "f%d", (int)o->o_value);
return;
case ASM_OPER_GREG:
break;
@@ -225,10 +227,10 @@
n = "ibr";
break;
case ASM_OPER_IMM:
- sprintf(buf, "0x%lx", o->o_value);
+ snprintf(buf, buflen, "0x%lx", o->o_value);
return;
case ASM_OPER_IP:
- strcpy(buf, "ip");
+ strlcpy(buf, "ip", buflen);
return;
case ASM_OPER_ITR:
n = "itr";
@@ -249,22 +251,22 @@
n = "pmd";
break;
case ASM_OPER_PR:
- strcpy(buf, "pr");
+ strlcpy(buf, "pr", buflen);
return;
case ASM_OPER_PR_ROT:
- strcpy(buf, "pr.rot");
+ strlcpy(buf, "pr.rot", buflen);
return;
case ASM_OPER_PREG:
- sprintf(buf, "p%d", (int)o->o_value);
+ snprintf(buf, buflen, "p%d", (int)o->o_value);
return;
case ASM_OPER_PSR:
- strcpy(buf, "psr");
+ strlcpy(buf, "psr", buflen);
return;
case ASM_OPER_PSR_L:
- strcpy(buf, "psr.l");
+ strlcpy(buf, "psr.l", buflen);
return;
case ASM_OPER_PSR_UM:
- strcpy(buf, "psr.um");
+ strlcpy(buf, "psr.um", buflen);
return;
case ASM_OPER_RR:
n = "rr";
@@ -273,16 +275,21 @@
KASSERT(0);
break;
}
- if (n[0] != '\0')
- buf += sprintf(buf, "%s[", n);
+ if (n[0] != '\0') {
+ l = snprintf(buf, buflen, "%s[", n);
+ buf += l;
+ buflen -= l;
+ }
switch ((int)o->o_value) {
- case 1: strcpy(buf, "gp"); buf += 2; break;
- case 12: strcpy(buf, "sp"); buf += 2; break;
- case 13: strcpy(buf, "tp"); buf += 2; break;
- default: buf += sprintf(buf, "r%d", (int)o->o_value); break;
+ case 1: l = strlcpy(buf, "gp", buflen); break;
+ case 12: l = strlcpy(buf, "sp", buflen); break;
+ case 13: l = strlcpy(buf, "tp", buflen); break;
+ default: l += snprintf(buf, buflen, "r%d", (int)o->o_value); break;
}
+ buf += l;
+ buflen -= l;
if (n[0] != '\0')
- strcpy(buf, "]");
+ strlcpy(buf, "]", buflen);
}
void
@@ -313,7 +320,7 @@
/* Predicate. */
if (i->i_oper[0].o_value != 0) {
- asm_operand(i->i_oper+0, buf, ip);
+ asm_operand(i->i_oper+0, buf, sizeof(buf), ip);
printf("(%s)", buf);
w = strlen(buf);
} else
@@ -322,12 +329,12 @@
printf(" ");
/* Mnemonic & completers. */
- asm_mnemonic(i->i_op, buf);
- printf(buf);
+ asm_mnemonic(i->i_op, buf, sizeof(buf));
+ printf("%s", buf);
w = strlen(buf);
n = 0;
while (n < i->i_ncmpltrs) {
- asm_completer(i->i_cmpltr + n, buf);
+ asm_completer(i->i_cmpltr + n, buf, sizeof(buf));
printf(buf);
w += strlen(buf);
n++;
@@ -345,8 +352,8 @@
else
printf(", ");
}
- asm_operand(i->i_oper + n, buf, ip);
- printf(buf);
+ asm_operand(i->i_oper + n, buf, sizeof(buf), ip);
+ printf("%s", buf);
n++;
}
printf("\n");
diff -r e68622ff706c -r 51f165f97517 sys/arch/ia64/stand/common/boot.c
--- a/sys/arch/ia64/stand/common/boot.c Tue Mar 25 17:30:14 2014 +0000
+++ b/sys/arch/ia64/stand/common/boot.c Tue Mar 25 18:35:32 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: boot.c,v 1.5 2009/07/20 04:59:03 kiyohara Exp $ */
+/* $NetBSD: boot.c,v 1.6 2014/03/25 18:35:32 christos Exp $ */
/*-
* Copyright (c) 1998 Michael Smith <msmith%freebsd.org@localhost>
@@ -64,7 +64,8 @@
/* XXX maybe we should discard everything and start again? */
if (file_findfile(NULL, NULL) != NULL) {
- sprintf(command_errbuf, "can't boot '%s', kernel module already loaded", argv[1]);
+ command_seterr("can't boot '%s', kernel module already loaded",
+ argv[1]);
return(CMD_ERROR);
}
@@ -88,7 +89,7 @@
* Loaded anything yet?
*/
if ((fp = file_findfile(NULL, NULL)) == NULL) {
- command_errmsg = "no bootable kernel";
+ command_seterr("no bootable kernel");
return(CMD_ERROR);
}
@@ -107,7 +108,7 @@
return(CMD_ERROR);
/* Call the exec handler from the loader matching the kernel */
- command_errmsg = strerror(file_formats[fp->f_loader]->l_exec(fp));
+ command_seterr("%s", strerror(file_formats[fp->f_loader]->l_exec(fp));
return(CMD_ERROR);
}
@@ -131,7 +132,7 @@
case 2:
howlong = strtol(argv[1], &cp, 0);
if (*cp != 0) {
- sprintf(command_errbuf, "bad delay '%s'", argv[1]);
+ command_seterr("bad delay '%s'", argv[1]);
return(CMD_ERROR);
}
/* FALLTHROUGH */
@@ -139,7 +140,7 @@
return(autoboot(howlong, prompt));
}
- command_errmsg = "too many arguments";
+ command_seterr("too many arguments");
return(CMD_ERROR);
}
@@ -184,7 +185,7 @@
loadakernel(0, 0, argv);
kernelname = getenv("kernelname");
if (kernelname == NULL) {
- command_errmsg = "no valid kernel found";
+ command_seterr("no valid kernel found");
return(CMD_ERROR);
}
}
@@ -294,7 +295,7 @@
if (getenv("vfs.root.mountfrom") != NULL)
return(0);
- sprintf(lbuf, "%s/etc/fstab", rootdev);
+ snprintf(lbuf, sizeof(lbuf), "%s/etc/fstab", rootdev);
if ((fd = open(lbuf, O_RDONLY)) < 0)
return(1);
@@ -333,7 +334,7 @@
fstyp = strdup(ep);
/* build the final result and save it */
- sprintf(lbuf, "%s:%s", fstyp, dev);
+ snprintf(lbuf, sizeof(lbuf), "%s:%s", fstyp, dev);
free(dev);
free(fstyp);
setenv("vfs.root.mountfrom", lbuf, 0);
diff -r e68622ff706c -r 51f165f97517 sys/arch/ia64/stand/common/bootstrap.h
--- a/sys/arch/ia64/stand/common/bootstrap.h Tue Mar 25 17:30:14 2014 +0000
+++ b/sys/arch/ia64/stand/common/bootstrap.h Tue Mar 25 18:35:32 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bootstrap.h,v 1.8 2012/12/27 20:21:50 martin Exp $ */
+/* $NetBSD: bootstrap.h,v 1.9 2014/03/25 18:35:32 christos Exp $ */
/*-
* Copyright (c) 1998 Michael Smith <msmith%freebsd.org@localhost>
@@ -50,10 +50,10 @@
#define DEVT_CD 3
};
-/* Commands and return values; nonzero return sets command_errmsg != NULL */
typedef int (bootblk_cmd_t)(int argc, char *argv[]);
-extern char *command_errmsg;
-extern char command_errbuf[]; /* XXX blah, length */
+int command_seterr(const char *fmt, ...) __printflike(1, 2);
+const char *command_geterr(void);
+
#define CMD_OK 0
#define CMD_ERROR 1
diff -r e68622ff706c -r 51f165f97517 sys/arch/ia64/stand/common/commands.c
--- a/sys/arch/ia64/stand/common/commands.c Tue Mar 25 17:30:14 2014 +0000
Home |
Main Index |
Thread Index |
Old Index