btrfs-progs: build warning hunting routine
cover btrfs-progs: build warning hunting routine
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(-)
Signature · 1 line
2.27.0
PATCH 1/2 btrfs-progs: convert/ext2: fix the pointer sign warning
[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.
--- convert/source-ext2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
convert/source-ext2.c +1 -1
@@ -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;
Signature · 1 line
2.27.0
PATCH 2/2 btrfs-progs: Fix seemly wrong format overflow warning
In reply to Qu Wenruo[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.
--- common/fsfeatures.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
common/fsfeatures.c +1 -1
@@ -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); }
Signature · 1 line
2.27.0
Quoted 5 lines · Qu Wenruo
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.