macro: introduce a nice macro for disabling -Wformat-nonliteral temporarily
This commit is contained in:
+2
-3
@@ -703,22 +703,21 @@ int log_meta_object(
|
||||
return r;
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
static void log_assert(int level, const char *text, const char *file, int line, const char *func, const char *format) {
|
||||
static char buffer[LINE_MAX];
|
||||
|
||||
if (_likely_(LOG_PRI(level) > log_max_level))
|
||||
return;
|
||||
|
||||
DISABLE_WARNING_FORMAT_NONLITERAL;
|
||||
snprintf(buffer, sizeof(buffer), format, text, file, line, func);
|
||||
REENABLE_WARNING;
|
||||
|
||||
char_array_0(buffer);
|
||||
log_abort_msg = buffer;
|
||||
|
||||
log_dispatch(level, file, line, func, NULL, NULL, buffer);
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
noreturn void log_assert_failed(const char *text, const char *file, int line, const char *func) {
|
||||
log_assert(LOG_CRIT, text, file, line, func, "Assertion '%s' failed at %s:%u, function %s(). Aborting.");
|
||||
|
||||
@@ -51,6 +51,10 @@
|
||||
_Pragma("GCC diagnostic push"); \
|
||||
_Pragma("GCC diagnostic ignored \"-Wdeclaration-after-statement\"")
|
||||
|
||||
#define DISABLE_WARNING_FORMAT_NONLITERAL \
|
||||
_Pragma("GCC diagnostic push"); \
|
||||
_Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\"")
|
||||
|
||||
#define REENABLE_WARNING \
|
||||
_Pragma("GCC diagnostic pop")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user