Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/lib/libsa Make libsa's vsnprintf() work as expected when...



details:   https://anonhg.NetBSD.org/src/rev/a13cc452e0a2
branches:  trunk
changeset: 934081:a13cc452e0a2
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sat Jun 06 15:45:47 2020 +0000

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

diffstat:

 sys/lib/libsa/subr_prf.c |  13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diffs (34 lines):

diff -r c675ef264101 -r a13cc452e0a2 sys/lib/libsa/subr_prf.c
--- a/sys/lib/libsa/subr_prf.c  Sat Jun 06 14:30:44 2020 +0000
+++ b/sys/lib/libsa/subr_prf.c  Sat Jun 06 15:45:47 2020 +0000
@@ -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 @@
 #endif /* LIBSA_PRINTF_LONGLONG_SUPPORT */
 
 static void
+null_sputchar(int c)
+{
+       sbuf++;
+}
+
+static void
 sputchar(int c)
 {
 
@@ -147,8 +153,9 @@
 
        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;
 }
 



Home | Main Index | Thread Index | Old Index