]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: add `FMT_NSTD()` for non-standard printf exts
authorDavid Lamparter <equinox@diac24.net>
Fri, 26 Mar 2021 17:11:21 +0000 (18:11 +0100)
committerDavid Lamparter <equinox@diac24.net>
Tue, 30 Mar 2021 20:32:59 +0000 (22:32 +0200)
... 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 <equinox@diac24.net>
lib/printfrr.h
tests/lib/test_printfrr.c

index 9dd20f0a8ff677bba9082877cc32edc2ebb07a2b..8245a664b3187df8c90abe32a87de61c75972de8 100644 (file)
@@ -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
index 6d64615fafb54a45efc34fc8e511dd18c0ef75cd..5a8d10e9b78ffe0b74a6a6f60af6aeda64ce1963 100644 (file)
@@ -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)