From fd8f712f31227ebfc3ecca63a7a3a5c3f15727d9 Mon Sep 17 00:00:00 2001 From: "Kaleb S. KEITHLEY" Date: Thu, 14 Sep 2017 13:33:09 -0400 Subject: core (named threads): flood of -Wformat-truncation warnings with gcc-7.1 Starting in Fedora 26 which has gcc-7.1.x, -Wformat-trunction is enabled with -Wformat, resulting in a flood of new warnings. This many warnings is a concern because it makes it hard(er) to see other warnings that should be addressed. An example is at https://kojipkgs.fedoraproject.org//packages/glusterfs/3.12.0/1.fc28/data/logs/x86_64/build.log For more info see https://review.gluster.org/#/c/18267/ I can't find much (or good) documentation on the heuristics the compiler uses for this warning. In the case of printing integer types it appears it looks at the available space in the destination and the range of values for the variable and/or its type. To address the specific question about why 0x3ff versus 0xfff to mask the value, either would suffice to hint to the compiler that the printed value will fit in three characters. But the loop is from 0...1023 (or 0...0x3ff if you prefer) so I chose that as a more "accurate" mask to use as it exactly matches the range of values of the loop. Fixes: bz#1492847 Change-Id: I6e309ba42159841131d8241bfc0566ef09e00aa9 --- xlators/features/changelog/lib/src/gf-history-changelog.c | 4 ++-- xlators/features/changelog/src/changelog-rpc.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'xlators/features') diff --git a/xlators/features/changelog/lib/src/gf-history-changelog.c b/xlators/features/changelog/lib/src/gf-history-changelog.c index 7b973b674a4..fd92dd7ed0b 100644 --- a/xlators/features/changelog/lib/src/gf-history-changelog.c +++ b/xlators/features/changelog/lib/src/gf-history-changelog.c @@ -618,8 +618,8 @@ gf_history_consume (void * data) curr->retval = 0; memset (curr->changelog, '\0', PATH_MAX); - snprintf (thread_name, sizeof(thread_name), "%s%d", - "clogc", iter + 1); + snprintf (thread_name, sizeof(thread_name), + "clogc%03hx", ((iter + 1) & 0x3ff)); ret = gf_thread_create (&th_id[iter], NULL, gf_changelog_consume_wrap, curr, diff --git a/xlators/features/changelog/src/changelog-rpc.c b/xlators/features/changelog/src/changelog-rpc.c index 793e7a8aff4..9027fe10a2a 100644 --- a/xlators/features/changelog/src/changelog-rpc.c +++ b/xlators/features/changelog/src/changelog-rpc.c @@ -116,7 +116,7 @@ changelog_init_rpc_threads (xlator_t *this, changelog_priv_t *priv, /* spawn dispatcher threads */ for (; j < nr_dispatchers; j++) { snprintf (thread_name, sizeof(thread_name), - "%s%d", "clogd", j); + "clogd%03hx", (j & 0x3ff)); ret = gf_thread_create (&priv->ev_dispatcher[j], NULL, changelog_ev_dispatch, conn, thread_name); -- cgit