All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 2/2] btrfs-progs: Fix seemly wrong format overflow warning
Date: Tue, 23 Jun 2020 13:48:04 +0800	[thread overview]
Message-ID: <20200623054804.67175-3-wqu@suse.com> (raw)
In-Reply-To: <20200623054804.67175-1-wqu@suse.com>

[WARNING]
When compiling btrfs-progs, the following warning pops up:
  In file included from /usr/include/stdio.h:867,
                   from ./kerncompat.h:22,
                   from common/fsfeatures.c:17:
  In function 'printf',
      inlined from 'process_features' at common/fsfeatures.c:192:4,
      inlined from 'btrfs_process_runtime_features' at common/fsfeatures.c:205:2:
  /usr/include/bits/stdio2.h:107:10: warning: '%s' directive argument is null [-Wformat-overflow=]
    107 |   return __printf_chk (__USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ());
        |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This only occur with default make parameters. If compiling with D=1, the
warning just disappears.

The involved tool chain is:
- GCC 10.1.0

[CAUSE]
The offending code is:
  static void process_features(u64 flags, enum feature_source source)
  {
  ...
		if (flags & feat->flag) {
			printf("Turning ON incompat feature '%s': %s\n",
				feat->name, feat->desc);
		}
  ...
  }

Currently, there is no runtime/fs feature without a name nor
description.
So we shouldn't hit a feature with NULL as name nor description.

This looks like a bug in GCC though.

[WORKAROUND]
However can workaround it by doing an explicit check on feat->name and
feat->desc to teach GCC not to do a wrong warning.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 common/fsfeatures.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/fsfeatures.c b/common/fsfeatures.c
index ae075daf..195a77c3 100644
--- a/common/fsfeatures.c
+++ b/common/fsfeatures.c
@@ -188,7 +188,7 @@ static void process_features(u64 flags, enum feature_source source)
 	for (i = 0; i < array_size; i++) {
 		const struct btrfs_feature *feat = get_feature(i, source);
 
-		if (flags & feat->flag) {
+		if (flags & feat->flag && feat->name && feat->desc) {
 			printf("Turning ON incompat feature '%s': %s\n",
 				feat->name, feat->desc);
 		}
-- 
2.27.0


  parent reply	other threads:[~2020-06-23  5:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-23  5:48 [PATCH 0/2] btrfs-progs: build warning hunting routine Qu Wenruo
2020-06-23  5:48 ` [PATCH 1/2] btrfs-progs: convert/ext2: fix the pointer sign warning Qu Wenruo
2020-06-23  5:48 ` Qu Wenruo [this message]
2020-06-24 15:46 ` [PATCH 0/2] btrfs-progs: build warning hunting routine David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200623054804.67175-3-wqu@suse.com \
    --to=wqu@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.