-Wmissing-parameter-type dnl
-Wshadow dnl
-Wno-gnu-folding-constant dnl
+ -Wsuggest-attribute=format dnl
dnl GCC enables this with -Wall in C++, and that generates a
dnl lot of warnings that have on average a low value to fix.
-Wno-sign-compare dnl
/**
* @brief Logging function for libkmod integration.
*/
-static void log_kmod(void *data, int priority, const char *file, int line,
+static ATTR_FORMAT_PRINTF(6, 0)
+void log_kmod(void *data, int priority, const char *file, int line,
const char *fn, const char *format, va_list args)
{
char *str;
goto error;
}
+ /*
+ * Parameter 2 of kmod_set_log_fn generates a
+ * -Wsuggest-attribute=formatkmod_set_log_fn warning that we can't fix,
+ * ignore it.
+ */
+ DIAGNOSTIC_PUSH
+ DIAGNOSTIC_IGNORE_SUGGEST_ATTRIBUTE_FORMAT
kmod_set_log_fn(*ctx, log_kmod, NULL);
+ DIAGNOSTIC_POP
ret = kmod_load_resources(*ctx);
if (ret < 0) {
ERR("Failed to load kmod library resources");
* remaining space left in packet and write, since mutual exclusion
* protects us from concurrent writes.
*/
-static
+static ATTR_FORMAT_PRINTF(2, 3)
int lttng_metadata_printf(struct ust_registry_session *session,
const char *fmt, ...)
{
if (entry->start.signedness) {
ret = lttng_metadata_printf(session,
- "%lld", (long long) entry->start.value);
+ "%" PRId64, entry->start.value);
} else {
ret = lttng_metadata_printf(session,
- "%llu", entry->start.value);
+ "%" PRIu64, entry->start.value);
}
if (ret) {
goto end;
} else {
if (entry->end.signedness) {
ret = lttng_metadata_printf(session,
- " ... %lld,\n",
- (long long) entry->end.value);
+ " ... %" PRId64 ",\n",
+ entry->end.value);
} else {
ret = lttng_metadata_printf(session,
- " ... %llu,\n",
+ " ... %" PRIu64 ",\n",
entry->end.value);
}
}
return ret >= 0 ? 0 : ret;
}
-static
+static ATTR_FORMAT_PRINTF(2, 3)
void xml_error_handler(void *ctx, const char *format, ...)
{
char *errMsg;
#define ASSERT_LOCKED(lock) LTTNG_ASSERT(pthread_mutex_trylock(&lock))
+/* Attribute suitable to tag functions as having printf()-like arguments. */
+#define ATTR_FORMAT_PRINTF(_string_index, _first_to_check) \
+ __attribute__((format(printf, _string_index, _first_to_check)))
+
+/* Macros used to ignore specific compiler diagnostics. */
+
+#define DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
+#define DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
+
+#if defined(__clang__)
+ /* Clang */
+# define DIAGNOSTIC_IGNORE_SUGGEST_ATTRIBUTE_FORMAT
+#else
+ /* GCC */
+# define DIAGNOSTIC_IGNORE_SUGGEST_ATTRIBUTE_FORMAT \
+ _Pragma("GCC diagnostic ignored \"-Wsuggest-attribute=format\"")
+#endif
+
/*
* lttng_strncpy returns 0 on success, or nonzero on failure.
* It checks that the @src string fits into @dst_len before performing
#include <unistd.h>
#include <common/compat/tid.h>
+#include <common/macros.h>
#include "signal-helper.h"
#include "utils.h"
{ NULL, 0, 0, NULL, 0 }
};
-static void debug_printf(const char *format, ...)
+static ATTR_FORMAT_PRINTF(1, 2)
+void debug_printf(const char *format, ...)
{
va_list args;
va_start(args, format);
#include <unistd.h>
#include <common/compat/tid.h>
+#include <common/macros.h>
#include "signal-helper.h"
#include "utils.h"
{ NULL, 0, 0, NULL, 0 }
};
-static void debug_printf(const char *format, ...)
+static ATTR_FORMAT_PRINTF(1, 2)
+void debug_printf(const char *format, ...)
{
va_list args;
va_start(args, format);
#include <lttng/lttng-error.h>
#include <common/macros.h>
+#include <common/macros.h>
+
struct validation_ctx {
xmlSchemaParserCtxtPtr parser_ctx;
xmlSchemaPtr schema;
CMD_ERROR
};
-static
+static ATTR_FORMAT_PRINTF(2, 3)
void xml_error_handler(void *ctx, const char *format, ...)
{
char *err_msg;