diff options
author | 2019-10-08 11:00:59 +0300 | |
---|---|---|
committer | 2019-10-08 11:00:59 +0300 | |
commit | 1af202370e38a1bbdac5d8619bfa580188a0b802 (patch) | |
tree | c4c2a932c31870705ac07a9ddde7afaa0b3c25ef /include | |
parent | 9528fa6c6be231137f55bef86864f0d85ec4baf9 (diff) | |
download | librin-1af202370e38a1bbdac5d8619bfa580188a0b802.tar.gz librin-1af202370e38a1bbdac5d8619bfa580188a0b802.tar.bz2 librin-1af202370e38a1bbdac5d8619bfa580188a0b802.zip |
diagnostic: tag functions as printf-style.
This allows the compiler to check the format string and give
warnings accordingly.
Signed-off-by: Gediminas Jakutis <gediminas@varciai.lt>
Diffstat (limited to 'include')
-rw-r--r-- | include/rin/definitions.h | 10 | ||||
-rw-r--r-- | include/rin/diagnostic.h | 9 |
2 files changed, 15 insertions, 4 deletions
diff --git a/include/rin/definitions.h b/include/rin/definitions.h index 19dde14..b8b6da3 100644 --- a/include/rin/definitions.h +++ b/include/rin/definitions.h @@ -26,6 +26,12 @@ /* weak symbols */ # define WEAK_SYM __attribute__((weak)) + +/* allow the compiler to check varargs */ +/* +# define FORMAT_STRING(a, b) __attribute__((format (printf, a, b))) +*/ + /* optimizing likely / unlikely branches */ # define likely(a) (__builtin_expect(!!(a), 1)) # define unlikely(a) (__builtin_expect((a), 0)) @@ -35,6 +41,9 @@ /* weak symbols */ # define WEAK_SYM __declspec(selectany) + +# define FORMAT_STRING(a, b) + /* optimizing likely / unlikely branches */ # define likely(a) (a) # define unlikely(a) (a) @@ -42,6 +51,7 @@ /* the rest – NOOP */ #else # define WEAK_SYM +# define FORMAT_STRING(a, b) # define likely(a) (a) # define unlikely(a) (a) #endif diff --git a/include/rin/diagnostic.h b/include/rin/diagnostic.h index de925cc..128e059 100644 --- a/include/rin/diagnostic.h +++ b/include/rin/diagnostic.h @@ -21,6 +21,7 @@ #ifndef LIBRIN_DIAGNOSTIC_INCLUDED #define LIBRIN_DIAGNOSTIC_INCLUDED +#include "rin/definitions.h" #include <stdio.h> #define RIN_DIAG_SET 1 @@ -42,9 +43,9 @@ enum rin_diag_outstream { int rin_diag_flags(int flag, int action); int rin_diag_set_outstream(enum rin_diag_outstream channel, FILE *stream); -void rin_err(const char *format, ...); -void rin_fixme(const char *format, ...); -void rin_warn(const char *format, ...); -void rin_info(const char *format, ...); +void rin_err(const char *format, ...) FORMAT_STRING(1, 2); +void rin_fixme(const char *format, ...) FORMAT_STRING(1, 2); +void rin_warn(const char *format, ...) FORMAT_STRING(1, 2); +void rin_info(const char *format, ...) FORMAT_STRING(1, 2); #endif /* LIBRIN_DIAGNOSTIC_INCLUDED */ |