-Wshadow dnl
-Wno-gnu-folding-constant dnl
-Wsuggest-attribute=format dnl
+ -Wformat=2 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
if (ret) {
filter_msg = strdup(" [failed to retrieve filter]");
} else if (filter_str) {
- const char * const filter_fmt = " [filter: '%s']";
-
- filter_msg = (char *) malloc(strlen(filter_str) +
- strlen(filter_fmt) + 1);
- if (filter_msg) {
- sprintf(filter_msg, filter_fmt,
- filter_str);
+ if (asprintf(&filter_msg, " [filter: '%s']", filter_str) == -1) {
+ filter_msg = NULL;
}
}
if (ret) {
filter_msg = strdup(" [failed to retrieve filter]");
} else if (filter_str) {
- const char * const filter_fmt =
- " [filter: '%s']";
-
- filter_msg = (char *) malloc(strlen(filter_str) +
- strlen(filter_fmt) + 1);
- if (filter_msg) {
- sprintf(filter_msg, filter_fmt,
- filter_str);
+ if (asprintf(&filter_msg, " [filter: '%s']", filter_str) == -1) {
+ filter_msg = NULL;
}
}
#define ATTR_FORMAT_PRINTF(_string_index, _first_to_check) \
__attribute__((format(printf, _string_index, _first_to_check)))
+/* Attribute suitable to tag functions as having strftime()-like arguments. */
+#define ATTR_FORMAT_STRFTIME(_string_index) \
+ __attribute__((format(strftime, _string_index, 0)))
+
/* Macros used to ignore specific compiler diagnostics. */
#define DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
#if defined(__clang__)
/* Clang */
# define DIAGNOSTIC_IGNORE_SUGGEST_ATTRIBUTE_FORMAT
+# define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL \
+ _Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\"")
#else
/* GCC */
# define DIAGNOSTIC_IGNORE_SUGGEST_ATTRIBUTE_FORMAT \
_Pragma("GCC diagnostic ignored \"-Wsuggest-attribute=format\"")
+# define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL \
+ _Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\"")
#endif
/*
/* Get date and time for session path */
time(&rawtime);
timeinfo = localtime(&rawtime);
+ DIAGNOSTIC_PUSH
+ DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
ret = strftime(dst, len, format, timeinfo);
+ DIAGNOSTIC_POP
if (ret == 0) {
ERR("Unable to strftime with format %s at dst %p of len %zu", format,
dst, len);
int utils_get_count_order_u64(uint64_t x);
const char *utils_get_home_dir(void);
char *utils_get_user_home_dir(uid_t uid);
-size_t utils_get_current_time_str(const char *format, char *dst, size_t len);
+
+size_t utils_get_current_time_str(const char *format, char *dst, size_t len)
+ ATTR_FORMAT_STRFTIME(1);
+
int utils_get_group_id(const char *name, bool warn, gid_t *gid);
char *utils_generate_optstring(const struct option *long_options,
size_t opt_count);
home = "/tmp";
}
+ DIAGNOSTIC_PUSH
+ DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL
ret = snprintf(lh->health_sock_path, sizeof(lh->health_sock_path),
home_str, home);
+ DIAGNOSTIC_POP
if ((ret < 0) || (ret >= sizeof(lh->health_sock_path))) {
return -ENOMEM;
}
# -Wsystem-headers is needed to print warnings in the tracepoint
# description file.
-AM_CPPFLAGS += -I$(srcdir) -Wsystem-headers
+#
+# However, we see some -Wformat-nonliteral warnings in some system headers,
+# so disable that.
+AM_CPPFLAGS += -I$(srcdir) -Wsystem-headers -Wno-format-nonliteral
# Set LIBS to nothing so the application does not link on useless
# libraries.
}
handle = lttng_payload_view_pop_fd_handle(&view);
- ok(!handle, test_description);
+ ok(!handle, "%s", test_description);
fd_handle_put(handle);
}
lttng_payload_reset(&payload);
return;
fail:
- fail(test_description);
+ fail("%s", test_description);
lttng_payload_reset(&payload);
}
}
lttng_payload_reset(&payload);
- pass(test_description);
+ pass("%s", test_description);
fd_handle_put(handle);
return;
fail:
lttng_payload_reset(&payload);
- fail(test_description);
+ fail("%s", test_description);
fd_handle_put(handle);
}
}
lttng_payload_reset(&payload);
- pass(test_description);
+ pass("%s", test_description);
fd_handle_put(handle1);
fd_handle_put(handle2);
fd_handle_put(view_handle1);
return;
fail:
lttng_payload_reset(&payload);
- fail(test_description);
+ fail("%s", test_description);
fd_handle_put(handle1);
fd_handle_put(handle2);
fd_handle_put(view_handle1);