From 849252c6a48b428dde3ad8930b40a2bdf9874cb7 Mon Sep 17 00:00:00 2001 From: Christian Göttsche Date: Thu, 6 Jun 2024 16:36:40 +0200 Subject: Add format attribute to log function and adjust format specifiers Annotate the common logging function sp_log_msgf() with the format attribute so compilers can check the used format string and passed arguments for discrepancies. Adjust the lineno printing by using %zu and the type size_t consistently. --- src/sp_utils.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/sp_utils.h') diff --git a/src/sp_utils.h b/src/sp_utils.h index 36caa52..1146db3 100644 --- a/src/sp_utils.h +++ b/src/sp_utils.h @@ -71,6 +71,11 @@ extern int sp_debug_stderr; #define GET_SUFFIX(x) (x == 1) ? "st" : ((x == 2) ? "nd" : "th") const char *get_ipaddr(void); +#if defined __has_attribute +# if __has_attribute (__format__) + __attribute__((__format__(printf, 4, 5))) +# endif +#endif void sp_log_msgf(char const* const restrict feature, int level, int type, char const* const restrict fmt, ...); int compute_hash(char const* const restrict filename, char *restrict file_hash); const zend_string *sp_zval_to_zend_string(const zval *); -- cgit v1.3