From c3dd8d8a4758d0700e16bb4355c97f1ef97fc460 Mon Sep 17 00:00:00 2001 From: Peter Keresztes Schmidt Date: Thu, 29 Apr 2021 00:11:24 +0200 Subject: [PATCH] Logger: Annotate logPrint with format attribute This allows the compiler to check for mismatches in the format string and the passed parameters. --- src/zm_logger.cpp | 2 +- src/zm_logger.h | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/zm_logger.cpp b/src/zm_logger.cpp index f8e7d7316..dd03ec9f2 100644 --- a/src/zm_logger.cpp +++ b/src/zm_logger.cpp @@ -415,7 +415,7 @@ void Logger::closeSyslog() { (void) closelog(); } -void Logger::logPrint(bool hex, const char * const filepath, const int line, const int level, const char *fstring, ...) { +void Logger::logPrint(bool hex, const char *filepath, int line, int level, const char *fstring, ...) { if (level > mEffectiveLevel) return; if (level < PANIC || level > DEBUG9) Panic("Invalid logger level %d", level); diff --git a/src/zm_logger.h b/src/zm_logger.h index b2a9bbeb0..79c3dfd7c 100644 --- a/src/zm_logger.h +++ b/src/zm_logger.h @@ -173,8 +173,13 @@ private: void closeSyslog(); void closeDatabase(); -public: - void logPrint(bool hex, const char * const filepath, const int line, const int level, const char *fstring, ...); + public: + void logPrint(bool hex, + const char *filepath, + int line, + int level, + const char *fstring, + ...) __attribute__((format(printf, 6, 7))); }; void logInit(const char *name, const Logger::Options &options=Logger::Options());