Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern - don't let arguments in macros have side effects
details: https://anonhg.NetBSD.org/src/rev/28a9f0c6e529
branches: trunk
changeset: 771514:28a9f0c6e529
user: christos <christos%NetBSD.org@localhost>
date: Thu Nov 24 01:14:19 2011 +0000
description:
- don't let arguments in macros have side effects
- nul terminate properly
diffstat:
sys/kern/subr_prf.c | 18 +++++++++---------
1 files changed, 9 insertions(+), 9 deletions(-)
diffs (55 lines):
diff -r f074fed52439 -r 28a9f0c6e529 sys/kern/subr_prf.c
--- a/sys/kern/subr_prf.c Thu Nov 24 01:11:04 2011 +0000
+++ b/sys/kern/subr_prf.c Thu Nov 24 01:14:19 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_prf.c,v 1.146 2011/11/22 21:25:04 christos Exp $ */
+/* $NetBSD: subr_prf.c,v 1.147 2011/11/24 01:14:19 christos Exp $ */
/*-
* Copyright (c) 1986, 1988, 1991, 1993
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.146 2011/11/22 21:25:04 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.147 2011/11/24 01:14:19 christos Exp $");
#include "opt_ddb.h"
#include "opt_ipkdb.h"
@@ -1079,10 +1079,10 @@
retval = kprintf(fmt, TOBUFONLY, &p, bf, ap);
if (bf && size > 0) {
/* nul terminate */
- if (p < bf + size)
- *p = '\0';
+ if (size <= retval)
+ bf[size - 1] = '\0';
else
- *--p = '\0';
+ bf[retval] = '\0';
}
return retval;
}
@@ -1205,9 +1205,9 @@
* Scan the format for conversions (`%' character).
*/
for (;;) {
- while (*fmt != '%' && *fmt) {
+ for (; *fmt != '%' && *fmt; fmt++) {
ret++;
- KPRINTF_PUTCHAR(*fmt++);
+ KPRINTF_PUTCHAR(*fmt);
}
if (*fmt == 0)
goto done;
@@ -1520,8 +1520,8 @@
KPRINTF_PUTCHAR('0');
/* the string or number proper */
- while (size--)
- KPRINTF_PUTCHAR(*cp++);
+ for (; size--; cp++)
+ KPRINTF_PUTCHAR(*cp);
/* left-adjusting padding (always blank) */
if (flags & LADJUST) {
n = width - realsz;
Home |
Main Index |
Thread Index |
Old Index