From c138111a3c27863308b6552a5527a9e821a3dc11 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Sun, 17 May 2020 17:05:30 -0700 Subject: Update to rra-c-util 8.2 and C TAP Harness 4.7 Update to rra-c-util 8.2: * Implement explicit_bzero with memset if it is not available. * Reformat all C source using clang-format 10. * Work around Test::Strict not skipping .git directories. * Fix warnings with perltidy 20190601 and Perl::Critic 1.134. * Fix warnings with Clang 10, GCC 10, and the Clang static analyzer. Update to C TAP Harness 4.7: * Fix warnings with GCC 10. * Reformat all C source using clang-format 10. * Fixed malloc error checking in bstrndup. --- portable/snprintf.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'portable/snprintf.c') diff --git a/portable/snprintf.c b/portable/snprintf.c index a42ef3b..a22e4e4 100644 --- a/portable/snprintf.c +++ b/portable/snprintf.c @@ -25,6 +25,28 @@ # define vsnprintf test_vsnprintf #endif +/* + * __attribute__ is available in gcc 2.5 and later, but only with gcc 2.7 + * could you use the __format__ form of the attributes, which is what we use + * (to avoid confusion with other macros). + */ +#ifndef __attribute__ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) +# define __attribute__(spec) /* empty */ +# endif +#endif + +/* + * Older Clang doesn't support __attribute__((fallthrough)) properly and + * complains about the empty statement that it is decorating. Suppress that + * warning. Also suppress warnings about unknown attributes to handle older + * Clang versions. + */ +#if !defined(__attribute__) && (defined(__llvm__) || defined(__clang__)) +# pragma GCC diagnostic ignored "-Wattributes" +# pragma GCC diagnostic ignored "-Wmissing-declarations" +#endif + /* Specific to rra-c-util, but only when debugging is enabled. */ #ifdef DEBUG_SNPRINTF # include @@ -64,7 +86,7 @@ * probably requires libm on most operating systems. Don't yet * support the exponent (e,E) and sigfig (g,G). Also, fmtint() * was pretty badly broken, it just wasn't being exercised in ways - * which showed it, so that's been fixed. Also, formated the code + * which showed it, so that's been fixed. Also, formatted the code * to mutt conventions, and removed dead code left over from the * original. Also, there is now a builtin-test, just compile with: * gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm @@ -366,7 +388,8 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args) break; case 'X': flags |= DP_F_UP; - /* fallthrough */ + __attribute__((fallthrough)); + /* fall through */ case 'x': flags |= DP_F_UNSIGNED; if (cflags == DP_C_SHORT) @@ -388,7 +411,8 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args) break; case 'E': flags |= DP_F_UP; - /* fallthrough */ + __attribute__((fallthrough)); + /* fall through */ case 'e': if (cflags == DP_C_LDOUBLE) fvalue = va_arg (args, LDOUBLE); @@ -398,7 +422,8 @@ static int dopr (char *buffer, size_t maxlen, const char *format, va_list args) break; case 'G': flags |= DP_F_UP; - /* fallthrough */ + __attribute__((fallthrough)); + /* fall through */ case 'g': flags |= DP_F_FP_G; if (cflags == DP_C_LDOUBLE) @@ -714,7 +739,7 @@ static int fmtfp (char *buffer, size_t *currlen, size_t maxlen, if (intpart != 0) { /* For each digit of INTPART, print one less fractional digit. */ - LLONG temp = intpart; + LLONG temp; for (temp = intpart; temp != 0; temp /= 10) --max; if (max < 0) -- cgit v1.2.3