From d0050295779c3f05069f68e723048cc51645377d Mon Sep 17 00:00:00 2001 From: Ali Mashtizadeh Date: Tue, 27 Jan 2015 10:33:44 -0800 Subject: [PATCH] Fix sprintf and snprintf to always null terminate --- lib/libc/printf.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/libc/printf.c b/lib/libc/printf.c index e6a0ada..d426293 100644 --- a/lib/libc/printf.c +++ b/lib/libc/printf.c @@ -268,6 +268,8 @@ int sprintf(char *str, const char *fmt, ...) ret = kvprintf(fmt, strputc, &state, ap); va_end(ap); + state.cur[0] = '\0'; + return ret; } @@ -285,6 +287,8 @@ int snprintf(char *str, size_t n, const char *fmt, ...) ret = kvprintf(fmt, strputc, &state, ap); va_end(ap); + state.cur[0] = '\0'; + return ret; }