btrfs-progs: convert: fix the pointer sign warning for ext2 label

[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 label 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>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Qu Wenruo 2020-06-23 13:48:03 +08:00 committed by David Sterba
parent fba57b689a
commit ac75513621

View File

@ -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;