Module Name:    src
Committed By:   thorpej
Date:           Sat Jun  6 15:45:47 UTC 2020

Modified Files:
        src/sys/lib/libsa: subr_prf.c

Log Message:
Make libsa's vsnprintf() work as expected when passed a NULL
destinatino buffer.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/lib/libsa/subr_prf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/lib/libsa/subr_prf.c
diff -u src/sys/lib/libsa/subr_prf.c:1.28 src/sys/lib/libsa/subr_prf.c:1.29
--- src/sys/lib/libsa/subr_prf.c:1.28	Sun Feb  3 11:59:43 2019
+++ src/sys/lib/libsa/subr_prf.c	Sat Jun  6 15:45:47 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_prf.c,v 1.28 2019/02/03 11:59:43 mrg Exp $	*/
+/*	$NetBSD: subr_prf.c,v 1.29 2020/06/06 15:45:47 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 1993
@@ -127,6 +127,12 @@ do {								\
 #endif	/* LIBSA_PRINTF_LONGLONG_SUPPORT */
 
 static void
+null_sputchar(int c)
+{
+	sbuf++;
+}
+
+static void
 sputchar(int c)
 {
 
@@ -147,8 +153,9 @@ vsnprintf(char *buf, size_t size, const 
 
 	sbuf = buf;
 	ebuf = buf + size - 1;
-	kdoprnt(sputchar, fmt, ap);
-	*sbuf = '\0';
+	kdoprnt(buf == NULL ? null_sputchar : sputchar, fmt, ap);
+	if (buf != NULL)
+		*sbuf = '\0';
 	return sbuf - buf;
 }
 

Reply via email to