From: David Lamparter Date: Fri, 26 Mar 2021 17:11:21 +0000 (+0100) Subject: lib: add `FMT_NSTD()` for non-standard printf exts X-Git-Tag: base_8.0~195^2~8 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=cb4928ce77c089ae521301776ed90e994c29800c;p=mirror%2Ffrr.git lib: add `FMT_NSTD()` for non-standard printf exts ... to suppress the warnings when using something that isn't quite ISO C compatible and would otherwise cause compiler warnings from `-Wformat`. Signed-off-by: David Lamparter --- diff --git a/lib/printfrr.h b/lib/printfrr.h index 9dd20f0a8f..8245a664b3 100644 --- a/lib/printfrr.h +++ b/lib/printfrr.h @@ -251,6 +251,31 @@ static inline ssize_t bputch(struct fbuf *buf, char ch) return 1; } +/* when using non-ISO-C compatible extension specifiers... */ + +#ifdef _FRR_ATTRIBUTE_PRINTFRR +#define FMT_NSTD_BEGIN +#define FMT_NSTD_END +#else /* !_FRR_ATTRIBUTE_PRINTFRR */ +#define FMT_NSTD_BEGIN \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wformat\"") \ + /* end */ +#define FMT_NSTD_END \ + _Pragma("GCC diagnostic pop") \ + /* end */ +#endif + +#define FMT_NSTD(expr) \ + ({ \ + typeof(expr) _v; \ + FMT_NSTD_BEGIN \ + _v = expr; \ + FMT_NSTD_END \ + _v; \ + }) \ + /* end */ + #ifdef __cplusplus } #endif diff --git a/tests/lib/test_printfrr.c b/tests/lib/test_printfrr.c index 6d64615faf..5a8d10e9b7 100644 --- a/tests/lib/test_printfrr.c +++ b/tests/lib/test_printfrr.c @@ -59,8 +59,8 @@ static void printcmp(const char *fmt, ...) errors++; } -static void printchk(const char *ref, const char *fmt, ...) PRINTFRR(2, 3); -static void printchk(const char *ref, const char *fmt, ...) +static int printchk(const char *ref, const char *fmt, ...) PRINTFRR(2, 3); +static int printchk(const char *ref, const char *fmt, ...) { va_list ap; char bufrr[256]; @@ -125,6 +125,7 @@ static void printchk(const char *ref, const char *fmt, ...) (int)(outpos[i].off_end - outpos[i].off_start), bufrr + outpos[i].off_start); printf("\n"); + return 0; } int main(int argc, char **argv)