All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] btrfs-progs: build warning hunting routine
@ 2020-06-23  5:48 Qu Wenruo
  2020-06-23  5:48 ` [PATCH 1/2] btrfs-progs: convert/ext2: fix the pointer sign warning Qu Wenruo
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Qu Wenruo @ 2020-06-23  5:48 UTC (permalink / raw)
  To: linux-btrfs

Two small cosmetic warning hunting with latest GCC/e2fsprogs.

Qu Wenruo (2):
  btrfs-progs: convert/ext2: fix the pointer sign warning
  btrfs-progs: Fix seemly wrong format overflow warning

 common/fsfeatures.c   | 2 +-
 convert/source-ext2.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

-- 
2.27.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] btrfs-progs: convert/ext2: fix the pointer sign warning
  2020-06-23  5:48 [PATCH 0/2] btrfs-progs: build warning hunting routine Qu Wenruo
@ 2020-06-23  5:48 ` Qu Wenruo
  2020-06-23  5:48 ` [PATCH 2/2] btrfs-progs: Fix seemly wrong format overflow warning Qu Wenruo
  2020-06-24 15:46 ` [PATCH 0/2] btrfs-progs: build warning hunting routine David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Qu Wenruo @ 2020-06-23  5:48 UTC (permalink / raw)
  To: linux-btrfs

[WARNING]
When compiling btrfs-progs, there is one warning from convert ext2 code:
  convert/source-ext2.c: In function 'ext2_open_fs':
  convert/source-ext2.c:91:44: warning: pointer targets in passing argument 1 of 'strndup' differ in signedness [-Wpointer-sign]
     91 |  cctx->volume_name = strndup(ext2_fs->super->s_volume_name, 16);
        |                              ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
        |                                            |
        |                                            __u8 * {aka unsigned char *}
  In file included from ./kerncompat.h:25,
                   from convert/source-ext2.c:19:
  /usr/include/string.h:175:35: note: expected 'const char *' but argument is of type '__u8 *' {aka 'unsigned char *'}
    175 | extern char *strndup (const char *__string, size_t __n)
        |                       ~~~~~~~~~~~~^~~~~~~~

The toolchain involved is:
- GCC 10.1.0
- e2fsprogs 1.45.6

[CAUSE]
Obviously, in the offending e2fsprogs, the volume lable is using u8,
which is unsigned char, not char.

  /*078*/	__u8	s_volume_name[EXT2_LABEL_LEN];	/* volume name, no NUL? */

[FIX]
Just do a forced conversion to suppress the warning is enough.
I don't think we need to apply -Wnopointer-sign yet.

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

diff --git a/convert/source-ext2.c b/convert/source-ext2.c
index f248249f..f11ef651 100644
--- a/convert/source-ext2.c
+++ b/convert/source-ext2.c
@@ -88,7 +88,7 @@ static int ext2_open_fs(struct btrfs_convert_context *cctx, const char *name)
 	cctx->blocksize = ext2_fs->blocksize;
 	cctx->block_count = ext2_fs->super->s_blocks_count;
 	cctx->total_bytes = ext2_fs->blocksize * ext2_fs->super->s_blocks_count;
-	cctx->volume_name = strndup(ext2_fs->super->s_volume_name, 16);
+	cctx->volume_name = strndup((char *)ext2_fs->super->s_volume_name, 16);
 	cctx->first_data_block = ext2_fs->super->s_first_data_block;
 	cctx->inodes_count = ext2_fs->super->s_inodes_count;
 	cctx->free_inodes_count = ext2_fs->super->s_free_inodes_count;
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] btrfs-progs: Fix seemly wrong format overflow warning
  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
  2020-06-24 15:46 ` [PATCH 0/2] btrfs-progs: build warning hunting routine David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: Qu Wenruo @ 2020-06-23  5:48 UTC (permalink / raw)
  To: linux-btrfs

[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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] btrfs-progs: build warning hunting routine
  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 ` [PATCH 2/2] btrfs-progs: Fix seemly wrong format overflow warning Qu Wenruo
@ 2020-06-24 15:46 ` David Sterba
  2 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2020-06-24 15:46 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs

On Tue, Jun 23, 2020 at 01:48:02PM +0800, Qu Wenruo wrote:
> Two small cosmetic warning hunting with latest GCC/e2fsprogs.
> 
> Qu Wenruo (2):
>   btrfs-progs: convert/ext2: fix the pointer sign warning
>   btrfs-progs: Fix seemly wrong format overflow warning

Added to devel, thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-06-24 15:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/2] btrfs-progs: Fix seemly wrong format overflow warning Qu Wenruo
2020-06-24 15:46 ` [PATCH 0/2] btrfs-progs: build warning hunting routine David Sterba

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.