Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern - use va_copy where needed
details: https://anonhg.NetBSD.org/src/rev/cbd922839e39
branches: trunk
changeset: 771448:cbd922839e39
user: christos <christos%NetBSD.org@localhost>
date: Mon Nov 21 01:44:26 2011 +0000
description:
- use va_copy where needed
- always nul terminate vsnprintf()
- make snprintf() call vsnprintf()
diffstat:
sys/kern/subr_prf.c | 30 +++++++++++++++++++-----------
1 files changed, 19 insertions(+), 11 deletions(-)
diffs (87 lines):
diff -r 4de1346d5fca -r cbd922839e39 sys/kern/subr_prf.c
--- a/sys/kern/subr_prf.c Mon Nov 21 00:24:24 2011 +0000
+++ b/sys/kern/subr_prf.c Mon Nov 21 01:44:26 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_prf.c,v 1.144 2011/11/20 23:01:18 christos Exp $ */
+/* $NetBSD: subr_prf.c,v 1.145 2011/11/21 01:44:26 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.144 2011/11/20 23:01:18 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_prf.c,v 1.145 2011/11/21 01:44:26 christos Exp $");
#include "opt_ddb.h"
#include "opt_ipkdb.h"
@@ -348,15 +348,18 @@
void
vlog(int level, const char *fmt, va_list ap)
{
+ va_list cap;
+ va_copy(cap, ap);
kprintf_lock();
klogpri(level); /* log the level first */
kprintf(fmt, TOLOG, NULL, NULL, ap);
if (!log_open)
- kprintf(fmt, TOCONS, NULL, NULL, ap);
+ kprintf(fmt, TOCONS, NULL, NULL, cap);
kprintf_unlock();
+ va_end(cap);
logwakeup(); /* wake up anyone waiting for log msgs */
}
@@ -627,11 +630,14 @@
void
db_vprintf(const char *fmt, va_list ap)
{
+ va_list cap;
+ va_copy(cap, ap);
/* No mutex needed; DDB pauses all processors. */
kprintf(fmt, TODDB, NULL, NULL, ap);
if (db_tee_msgbuf)
- kprintf(fmt, TOLOG, NULL, NULL, ap);
+ kprintf(fmt, TOLOG, NULL, NULL, cap);
+ va_end(cap);
}
#endif /* DDB */
@@ -1052,14 +1058,11 @@
{
int retval;
va_list ap;
- char *p;
- p = bf + size;
va_start(ap, fmt);
- retval = kprintf(fmt, TOBUFONLY, &p, bf, ap);
+ retval = vsnprintf(bf, size, fmt, ap);
va_end(ap);
- if (bf && p < bf + size)
- *p = '\0'; /* nul terminate */
+
return retval;
}
@@ -1074,8 +1077,13 @@
p = bf + size;
retval = kprintf(fmt, TOBUFONLY, &p, bf, ap);
- if (bf && p < bf + size)
- *p = '\0'; /* nul terminate */
+ if (bf && size > 0) {
+ /* nul terminate */
+ if (p < bf + size)
+ *p = '\0';
+ else
+ *--p = '\0';
+ }
return retval;
}
Home |
Main Index |
Thread Index |
Old Index