Make libsa's vsnprintf() work as expected when passed a NULL

destinatino buffer.
This commit is contained in:
thorpej 2020-06-06 15:45:47 +00:00
parent c012787efc
commit 30a26bde0a
1 changed files with 10 additions and 3 deletions

View File

@ -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
@ -126,6 +126,12 @@ do { \
} while (/*CONSTCOND*/0)
#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 char *fmt, va_list ap)
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;
}