scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 5ab34fe6b03c4e0938f17fe445e96bc19bf76768
parent 6bebff844a6aa4f95675dc7beae9ff24d06464b0
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Thu, 19 May 2022 18:53:46 +0200

libc: fix underflow in vsnprintf when size is 0

"If n is zero, nothing is written, and s may be a null pointer."

Diffstat:
Msrc/libc/stdio/vsnprintf.c | 3++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/libc/stdio/vsnprintf.c b/src/libc/stdio/vsnprintf.c @@ -19,7 +19,8 @@ vsnprintf(char *restrict s, size_t siz, const char *restrict fmt, va_list ap) if (s) { if (f.wp == f.rp) --f.wp; - *f.wp = '\0'; + if (siz != 0) + *f.wp = '\0'; } return r;