[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@xxxxxxxx>
---
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