Make printf() a bit more robust and allow NULL strings (print them as

"<null>"). It bad to have diagnostic printfs cause panics when they are
trying to tell you about another problem.
This commit is contained in:
David Greenman 1994-12-28 06:28:34 +00:00
parent be6a1d148e
commit 8f5067ba28

View File

@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)subr_prf.c 8.3 (Berkeley) 1/21/94
* $Id: subr_prf.c,v 1.6 1994/09/28 19:22:32 phk Exp $
* $Id: subr_prf.c,v 1.7 1994/10/02 17:35:23 phk Exp $
*/
#include <sys/param.h>
@ -371,6 +371,10 @@ kprintf(fmt, flags, tp, ap)
u_long ul;
int base, lflag, tmp, width;
char padc;
char nulstr[] = "<null>";
if (fmt == NULL)
return;
for (;;) {
padc = ' ';
@ -429,6 +433,8 @@ reswitch: switch (ch = *(u_char *)fmt++) {
break;
case 's':
p = va_arg(ap, char *);
if (p == NULL)
p = nulstr;
while (*p)
putchar(*p++, flags, tp);
break;