From: Mikko Johannes Koivunalho Date: Mon, 19 Aug 2019 17:11:04 +0000 (+0200) Subject: Initialize buffer to ensure it is empty X-Git-Tag: 0.13.0~10^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4c44483e2e253d5df55a69d5dab61a2b18f37dab;p=check Initialize buffer to ensure it is empty snprintf.c:918:31: warning: The left operand of '!=' is a garbage value for (strln = 0; value[strln] != '\0' && ~~~~~~~~~~~~ ^ Move "#include " from testing related code to main code because memset(3) depends on . Signed-off-by: Mikko Johannes Koivunalho --- diff --git a/lib/snprintf.c b/lib/snprintf.c index 9beabbd..09fc021 100644 --- a/lib/snprintf.c +++ b/lib/snprintf.c @@ -170,7 +170,6 @@ #if TEST_SNPRINTF #include /* For pow(3), NAN, and INFINITY. */ -#include /* For strcmp(3). */ #if defined(__NetBSD__) || \ defined(__FreeBSD__) || \ defined(__OpenBSD__) || \ @@ -263,6 +262,7 @@ #if !HAVE_SNPRINTF || !HAVE_VSNPRINTF #include /* For NULL, size_t, vsnprintf(3), and vasprintf(3). */ +#include /* For strcmp(3) and memset(3). */ #ifdef VA_START #undef VA_START #endif /* defined(VA_START) */ @@ -1076,6 +1076,10 @@ fmtflt(char *str, size_t *len, size_t size, LDOUBLE fvalue, int width, struct lconv *lc = localeconv(); #endif /* HAVE_LOCALECONV && HAVE_LCONV_DECIMAL_POINT */ + /* Initialize with memset because `var[n]={0}` is not supported by C90. */ + memset(iconvert, '\0', MAX_CONVERT_LENGTH); + memset(fconvert, '\0', MAX_CONVERT_LENGTH); + /* * AIX' man page says the default is 0, but C99 and at least Solaris' * and NetBSD's man pages say the default is 6, and sprintf(3) on AIX