This patch removes all the offending instances of -Wformat-nonliteral
and removes -Wno-format-nonliteral from the warning flags we enable.
In cases where we re-use the same format string multiple times, like:
const char *const msg = "Hello %d\n";
if (something) {
pass(msg, value);
} else {
fail(msg, value);
}
... my compiler (gcc (Arch Linux 9.2.1+
20200130-2) 9.2.1
20200130)
complains that the format string is not a literal, even though the `msg`
variable is const and assigned a literal. I've replaced these with a
macro.
In other places, we manually manipulate and craft format strings, to
I've just disabled the warning there.
The generated SWIG wrapper for the error appending functions cause some
warnings like this:
bt2/native_bt.c: In function ‘_wrap_current_thread_error_append_cause_from_component__varargs__’:
bt2/native_bt.c:7839:3: error: format not a string literal, argument types not checked [-Werror=format-nonliteral]
7839 | result = (bt_current_thread_error_append_cause_status)bt_current_thread_error_append_cause_from_component(arg1,(char const *)arg2,arg3,(char const *)arg4,ar
g5);
| ^~~~~~
Since we don't actually need these functions from the Python bindings,
I've made SWIG not generate a wrapper for them.
Change-Id: Ic6834dc44abce7be8e113e9cbf3f33a3f09809e2
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/3233
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
-Wnested-externs dnl
-Wwrite-strings dnl
-Wformat=2 dnl
- -Wno-format-nonliteral dnl
-Wstrict-aliasing dnl
-Wmissing-noreturn dnl
-Winit-self dnl
dir = g_dir_open(input->str, 0, &error);
if (!dir) {
- const char *fmt = "Failed to open directory %s: %s";
- BT_LOGW(fmt, input->str, error->message);
+#define BT_FMT "Failed to open directory %s: %s"
+ BT_LOGW(BT_FMT, input->str, error->message);
if (error->code == G_FILE_ERROR_ACCES) {
/* This is not a fatal error, we just skip it. */
status = AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_NO_MATCH;
goto end;
} else {
- BT_AUTODISC_LOGE_APPEND_CAUSE(fmt, input->str,
+ BT_AUTODISC_LOGE_APPEND_CAUSE(BT_FMT, input->str,
error->message);
goto error;
}
+#undef BT_FMT
}
saved_input_len = input->len;
void bt_bt2_init_from_bt2(void);
void bt_bt2_exit_handler(void);
+/*
+ * These functions cause some -Wformat-nonliteral warnings, but we don't need
+ * them. Ignore them, so that we can keep the warning turned on.
+ */
+%ignore bt_current_thread_error_append_cause_from_component;
+%ignore bt_current_thread_error_append_cause_from_component_class;
+%ignore bt_current_thread_error_append_cause_from_message_iterator;
+%ignore bt_current_thread_error_append_cause_from_unknown;
+
/*
* Define `__BT_IN_BABELTRACE_H` to allow specific headers to be
* included. This remains defined as long as we don't include the main
status = py_exc_to_status_component_class_clear(self_component_class,
log_level);
if (status < 0) {
- static const char *fmt =
- "Failed to call Python class's _bt_query_from_native() method: py-cls-addr=%p";
+#define BT_FMT "Failed to call Python class's _bt_query_from_native() method: py-cls-addr=%p"
BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING, log_level, BT_LOG_TAG,
- fmt, py_cls);
+ BT_FMT, py_cls);
BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT_CLASS(
- self_component_class, fmt, py_cls);
+ self_component_class, BT_FMT, py_cls);
+#undef BT_FMT
}
goto end;
}
size_t _tmp_fmt_size = (size_t) (fmt_ch - *out_fmt_ch); \
strncpy(_tmp_fmt, *out_fmt_ch, _tmp_fmt_size); \
_tmp_fmt[_tmp_fmt_size] = '\0'; \
+ _Pragma("GCC diagnostic push") \
+ _Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\"") \
_count = snprintf(*buf_ch, _size, _tmp_fmt, __VA_ARGS__); \
- BT_ASSERT_DBG(_count >= 0); \
+ _Pragma("GCC diagnostic pop") \
+ BT_ASSERT_DBG(_count >= 0); \
*buf_ch += MIN(_count, _size); \
} while (0)
fmt = ", %svalue=%" PRIx64;
}
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
if (field_class->common.type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER ||
field_class->common.type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION) {
if (!fmt) {
BUF_APPEND(fmt, PRFIELD(integer->value.u));
}
+#pragma GCC diagnostic pop
}
static inline void format_field(char **buf_ch, bool extended,
bt_common_abort();
}
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
sprintf(buf_start, spec, value);
+#pragma GCC diagnostic pop
if (sep_digits) {
bt_common_sep_digits(buf_start, digits_per_group, sep);
bt_common_abort();
}
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
sprintf(buf_start, spec, abs_value);
+#pragma GCC diagnostic pop
if (sep_digits) {
bt_common_sep_digits(buf_start, digits_per_group, sep);
i == bt_error_get_cause_count(error) - 1 ?
"%s%sERROR%s: " : "%s%sCAUSED BY%s ";
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
/* Print prefix */
g_string_append_printf(str, prefix_fmt,
codes.bold, codes.fg_bright_red, codes.reset);
+#pragma GCC diagnostic pop
g_free(error_cause_str);
error_cause_str = format_bt_error_cause(cause, columns,
status = bt_param_validation_validate(params, entries, &validate_error);
if (expected_error) {
- const char *fmt;
-
/* We expect a failure. */
ok(status == BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR,
"%s: validation fails", test_name);
ok(validate_error, "%s: error string is not NULL", test_name);
- fmt = "%s: error string contains expected string";
+#define BT_FMT "%s: error string contains expected string"
if (validate_error && strstr(validate_error, expected_error)) {
- pass(fmt, test_name);
+ pass(BT_FMT, test_name);
} else {
- fail(fmt, test_name);
+ fail(BT_FMT, test_name);
diag("could not find `%s` in `%s`", expected_error, validate_error);
}
+#undef BT_FMT
g_free(validate_error);
} else {
LOCK;
va_start(ap, fmt);
- if (asprintf(&skip_msg, fmt, ap) == -1) {
+ if (vasprintf(&skip_msg, fmt, ap) == -1) {
skip_msg = NULL;
}
va_end(ap);