Suppress warning: zero-length gnu_printf format string
PATCH 1/1 Suppress warning: zero-length gnu_printf format string
Warns about this line in check-qjson.c:
QObject *obj = qobject_from_json("");The obvious fix (add -Wno-format-zero-length to gcc_flags) doesn't work, because -Wall switches it on again. Fix by putting configured flags last.
--- configure | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
configure +3 -2
@@ -146,7 +146,8 @@ QEMU_CFLAGS="-I. -I\$(SRC_PATH) $QEMU_CFLAGS" LDFLAGS="-g $LDFLAGS" gcc_flags="-Wold-style-declaration -Wold-style-definition -Wtype-limits" -gcc_flags="-Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers $gcc_flags" +gcc_flags="-Wformat-security -Wformat-y2k -Wno-format-zero-length $gcc_flags" +gcc_flags="-Winit-self -Wignored-qualifiers $gcc_flags" gcc_flags="-Wmissing-include-dirs -Wempty-body -Wnested-externs $gcc_flags" gcc_flags="-fstack-protector-all $gcc_flags" cat > $TMPC << EOF
@@ -154,7 +155,7 @@ int main(void) { return 0; } EOF for flag in $gcc_flags; do if compile_prog "-Werror $QEMU_CFLAGS" "-Werror $flag" ; then - QEMU_CFLAGS="$flag $QEMU_CFLAGS" + QEMU_CFLAGS="$QEMU_CFLAGS $flag" fi done
Signature · 1 line
1.7.2.3
Quoted 27 lines · Markus Armbruster
Warns about this line in
check-qjson.c:QObject *obj = qobject_from_json("");The obvious fix (add -Wno-format-zero-length to
gcc_flags) doesn't work, because -Wall switches it on again. Fix by putting configured flags last.Signed-off-by Markus Armbruster<[email protected]>--- configure | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)configure +2
-1@@ -146,7 +146,8 @@ QEMU_CFLAGS="-I. -I\$(SRC_PATH) $QEMU_CFLAGS" LDFLAGS="-g $LDFLAGS" gcc_flags="-Wold-style-declaration -Wold-style-definition -Wtype-limits" -gcc_flags="-Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers $gcc_flags" +gcc_flags="-Wformat-security -Wformat-y2k -Wno-format-zero-length $gcc_flags" +gcc_flags="-Winit-self -Wignored-qualifiers $gcc_flags" gcc_flags="-Wmissing-include-dirs -Wempty-body -Wnested-externs $gcc_flags" gcc_flags="-fstack-protector-all $gcc_flags" cat> $TMPC<< EOF
configure int main(void) { return 0; } · line 161
Quoted 8 lines
configure +1
-1@@ -154,7 +155,7 @@ int main(void) { return 0; } EOF for flag in $gcc_flags; do if compile_prog "-Werror $QEMU_CFLAGS" "-Werror $flag" ; then - QEMU_CFLAGS="$flag $QEMU_CFLAGS" + QEMU_CFLAGS="$QEMU_CFLAGS $flag" fi done
Paolo
Quoted 6 lines · Markus Armbruster
Warns about this line in
check-qjson.c:
QObject *obj =qobject_from_json("");The obvious fix (add -Wno-format-zero-length to
gcc_flags) doesn't work, because -Wall switches it on again. Fix by putting configured flags last.
This would disable the flag globally. I'd rather disable the flag only for check-qjson.o or more generically, remove -Werror for checks. For example, there could be a check for how we handle invalid formats and then the sources would contain format strings that annoy GCC, but we wouldn't want warnings from that to stop the build.
Quoted 10 lines · Blue Swirl
Quoted 6 lines · Markus Armbruster
Warns about this line in
check-qjson.c:
QObject *obj =qobject_from_json("");The obvious fix (add -Wno-format-zero-length to
gcc_flags) doesn't work, because -Wall switches it on again. Fix by putting configured flags last.This would disable the flag globally. I'd rather disable the flag only for check-qjson.o
Is this warning worth the hassle? What's the problem with empty format strings?
Quoted 4 lines
or more generically, remove -Werror for checks. For
example, there could be a check for how we handle invalid formats and then the sources would contain format strings that annoy GCC, but we wouldn't want warnings from that to stop the build.
If you want to go that extra mile, feel free. For me, --disable-werror has been good enough.
Regardless, I think we need the second patch hunk, to prevent -Wall from trampling over $gcc_flags.
Quoted 10 lines · Markus Armbruster
Quoted 8 lines · Blue Swirl
Quoted 6 lines · Markus Armbruster
Warns about this line in
check-qjson.c:
QObject *obj =qobject_from_json("");The obvious fix (add -Wno-format-zero-length to
gcc_flags) doesn't work, because -Wall switches it on again. Fix by putting configured flags last.
Quoted 5 lines
Quoted 2 lines
This would disable the flag globally. I'd rather disable the flag only for check-qjson.o
Is this warning worth the hassle? What's the problem with empty format strings?
Your fix solves this specific case, but it also degrades the gcc checks of the mainstream code (slightly). I think the test suite need not follow the level of checking that should be applied to mainstream, or at least the warnings there should not be fatal.
Quoted 7 lines
Quoted 4 lines
or more generically, remove -Werror for checks. For example, there could be a check for how we handle invalid formats and then the sources would contain format strings that annoy GCC, but we wouldn't want warnings from that to stop the build.
If you want to go that extra mile, feel free. For me, --disable-werror has been good enough.
In that case, we could ignore the warning, since the only reporter is able to use a workaround ;-).
Quoted 2 lines
Regardless, I think we need the second patch hunk, to prevent -Wall from trampling over $gcc_flags.
I'm fine with that part.
PATCH 1/1 configure: Support disabling warnings in $gcc_flags
-Wall enables a bunch of warnings at once. configure puts it after $gcc_flags. This makes it impossible to disable warnings enabled by -Wall there. Fix by putting configured flags last.
--- configure | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
configure +1 -1
@@ -154,7 +155,7 @@ int main(void) { return 0; } EOF for flag in $gcc_flags; do if compile_prog "-Werror $QEMU_CFLAGS" "-Werror $flag" ; then - QEMU_CFLAGS="$flag $QEMU_CFLAGS" + QEMU_CFLAGS="$QEMU_CFLAGS $flag" fi done
Signature · 1 line
1.7.2.3
Blue Swirl
Applied[Qemu-devel] Re: [PATCH] configure: Support disabling warnings in $gcc_flags
Thanks, applied.
Quoted 25 lines · Markus Armbruster
-Wall enables a bunch of warnings at once. configure puts it after $gcc_flags. This makes it impossible to disable warnings enabled by -Wall there. Fix by putting configured flags last.
Signed-off-by Markus Armbruster <[email protected]>---
configure | 5 +++--1 files changed, 3 insertions(+), 2 deletions(-)configure +0
-0@@ -154,7 +155,7 @@ int main(void) { return 0; }EOF
for flag in $gcc_flags; do
ifcompile_prog"-Werror $QEMU_CFLAGS" "-Werror $flag" ; then
- QEMU_CFLAGS="$flag $QEMU_CFLAGS"
+ QEMU_CFLAGS="$QEMU_CFLAGS $flag"
fi
done--
1.7.2.3
Quoted 14 lines · Blue Swirl
Quoted 13 lines · Markus Armbruster
Quoted 10 lines · Blue Swirl
Quoted 6 lines · Markus Armbruster
Warns about this line in
check-qjson.c:
QObject *obj =qobject_from_json("");The obvious fix (add -Wno-format-zero-length to
gcc_flags) doesn't work, because -Wall switches it on again. Fix by putting configured flags last.This would disable the flag globally. I'd rather disable the flag only for check-qjson.o
Quoted 7 lines
Quoted 2 lines
Is this warning worth the hassle? What's the problem with empty format strings?
Your fix solves this specific case, but it also degrades the gcc checks of the mainstream code (slightly). I think the test suite need not follow the level of checking that should be applied to mainstream, or at least the warnings there should not be fatal.
"Degrade" implies we miss something that's "wrong" enough to be worth avoiding. What's wrong with empty format strings?
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
or more generically, remove -Werror for checks. For example, there could be a check for how we handle invalid formats and then the sources would contain format strings that annoy GCC, but we wouldn't want warnings from that to stop the build.
If you want to go that extra mile, feel free. For me, --disable-werror has been good enough.
Quoted 7 lines
In that case, we could ignore the warning, since the only reporter is able to use a workaround ;-).
Quoted 2 lines
Regardless, I think we need the second patch hunk, to prevent -Wall from trampling over $gcc_flags.
I'm fine with that part.
Reposted separately.
Quoted 19 lines · Markus Armbruster
Quoted 17 lines · Blue Swirl
Quoted 15 lines · Markus Armbruster
Quoted 10 lines · Blue Swirl
Quoted 6 lines · Markus Armbruster
Warns about this line in
check-qjson.c:
QObject *obj =qobject_from_json("");The obvious fix (add -Wno-format-zero-length to
gcc_flags) doesn't work, because -Wall switches it on again. Fix by putting configured flags last.This would disable the flag globally. I'd rather disable the flag only for check-qjson.o
Is this warning worth the hassle? What's the problem with empty format strings?
Quoted 7 lines
Quoted 4 lines
Your fix solves this specific case, but it also degrades the gcc checks of the mainstream code (slightly). I think the test suite need not follow the level of checking that should be applied to mainstream, or at least the warnings there should not be fatal.
"Degrade" implies we miss something that's "wrong" enough to be worth avoiding. What's wrong with empty format strings?
They generate useless calls to the formatting function, wasting performance (slightly). Since there are no calls currently, this is of course hypothetical.
We don't want those to appear in QEMU, but for test suite they may be acceptable (for example, to test empty format string handling) because test suite is not performance critical.
Quoted 25 lines · Blue Swirl
Quoted 24 lines · Markus Armbruster
Quoted 21 lines · Blue Swirl
Quoted 10 lines · Markus Armbruster
Quoted 8 lines · Blue Swirl
Quoted 6 lines · Markus Armbruster
Warns about this line in
check-qjson.c:QObject *obj = qobject_from_json("");The obvious fix (add -Wno-format-zero-length to
gcc_flags) doesn't work, because -Wall switches it on again. Fix by putting configured flags last.Quoted 5 lines
Quoted 2 lines
This would disable the flag globally. I'd rather disable the flag only for check-qjson.o
Is this warning worth the hassle? What's the problem with empty format strings?
Your fix solves this specific case, but it also degrades the gcc checks of the mainstream code (slightly). I think the test suite need not follow the level of checking that should be applied to mainstream, or at least the warnings there should not be fatal.
Quoted 6 lines
Quoted 2 lines
"Degrade" implies we miss something that's "wrong" enough to be worth avoiding. What's wrong with empty format strings?
They generate useless calls to the formatting function, wasting performance (slightly). Since there are no calls currently, this is of course hypothetical.
It is even more hypothetical when empty-format printfs are optimized away by GCC:
$ gcc -x c - -O2 -S -o -
#include <stdio.h>
main() { printf (""); }.file "" .text .p2align 4,,15
.globl main
.type main, @function
main:
.LFB11:
.cfi_startproc
rep
ret
.cfi_endproc
and other attribute-printf-marked functions are probably not noop when the format argument is empty.
Paolo
Quoted 59 lines · Paolo Bonzini
Quoted 32 lines · Blue Swirl
Quoted 29 lines · Markus Armbruster
Quoted 25 lines · Blue Swirl
Quoted 13 lines · Markus Armbruster
Quoted 10 lines · Blue Swirl
Quoted 7 lines · Markus Armbruster
Warns about this line in
check-qjson.c:
QObject *obj =qobject_from_json("");The obvious fix (add -Wno-format-zero-length to
gcc_flags) doesn't work, because -Wall switches it on again. Fix by putting configured flags last.Quoted 5 lines
Quoted 2 lines
This would disable the flag globally. I'd rather disable the flag only for check-qjson.o
Is this warning worth the hassle? What's the problem with empty format strings?
Your fix solves this specific case, but it also degrades the gcc checks of the mainstream code (slightly). I think the test suite need not follow the level of checking that should be applied to mainstream, or at least the warnings there should not be fatal.
Quoted 6 lines
Quoted 2 lines
"Degrade" implies we miss something that's "wrong" enough to be worth avoiding. What's wrong with empty format strings?
They generate useless calls to the formatting function, wasting performance (slightly). Since there are no calls currently, this is of course hypothetical.
It is even more hypothetical when empty-format printfs are optimized away by GCC:
$ gcc -x c - -O2 -S -o - #include <stdio.h> main() { printf (""); }.file ""
.text
.p2align 4,,15
.globl main
.type main, @function
main:
.LFB11:
.cfi_startproc
rep
ret
.cfi_endproc
Quoted 2 lines
and other attribute-printf-marked functions are probably not noop when the format argument is empty.
How is that? Does the warning message from qobject_from_json("") mean that GCC may optimize that call away?
Quoted 19 lines · Blue Swirl
Quoted 19 lines
It is even more hypothetical when empty-format printfs are optimized away by GCC:
$ gcc -x c - -O2 -S -o - #include<stdio.h> main() { printf (""); }.file "" .text .p2align 4,,15.globl main
.type main, @function
main:
.LFB11:
.cfi_startproc
rep
ret
.cfi_endproc
Quoted 5 lines
Quoted 2 lines
and other attribute-printf-marked functions are probably not noop when the format argument is empty.
How is that? Does the warning message from
qobject_from_json("")mean that GCC may optimize that call away?
I meant, the warning is likely bogus for most functions that do "something like printf" but it is not printf (like qobject_from_json, or asprintf). If the only good reason to have the warning is a hypothetical performance degradation, let's please turn it off, because this performance degradation isn't even there.
Paolo
Quoted 26 lines · Paolo Bonzini
Quoted 25 lines · Blue Swirl
Quoted 24 lines
It is even more hypothetical when empty-format printfs are optimized away by
GCC:$ gcc -x c - -O2 -S -o - #include<stdio.h> main() { printf (""); }.file ""
.text
.p2align 4,,15
.globl main
.type main, @function
main:
.LFB11:
.cfi_startproc
rep
ret
.cfi_endprocand other attribute-printf-marked functions are probably not noop when the
format argument is empty.
Quoted 8 lines
Quoted 2 lines
How is that? Does the warning message from
qobject_from_json("")mean that GCC may optimize that call away?I meant, the warning is likely bogus for most functions that do "something like printf" but it is not printf (like
qobject_from_json, or asprintf). If the only good reason to have the warning is a hypothetical performance degradation, let's please turn it off, because this performance degradation isn't even there.
Which functions are optimized away and which aren't? What would happen to for example monitor_printf("")? There are side effects, so it wouldn't be correct to remove a call like that, but those calls would still bring useless performance degradation.
Quoted 1 line · Blue Swirl
Which functions are optimized away and which aren't?
It's builtins only that are optimized away or otherwise inlined (printf, sprintf, etc.). Other calls stay, together with side effects and clock cycles.
Paolo
Quoted 7 lines · Paolo Bonzini
Quoted 2 lines · Blue Swirl
Which functions are optimized away and which aren't?
It's builtins only that are optimized away or otherwise inlined (printf, sprintf, etc.). Other calls stay, together with side effects and clock cycles.
Then the warning makes sense (slightly) and should remain on main QEMU side.
PATCH 1/1 Silence compiler warning in json test case
Quoted 11 lines · Blue Swirl
Quoted 7 lines · Paolo Bonzini
Quoted 2 lines · Blue Swirl
Which functions are optimized away and which aren't?
It's builtins only that are optimized away or otherwise inlined (printf, sprintf, etc.). Other calls stay, together with side effects and clock cycles.
Then the warning makes sense (slightly) and should remain on main QEMU side.
From: Jan Kiszka <[email protected]>
This avoids
error: zero-length gnu_printf format string
--- check-qjson.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
check-qjson.c +3 -1
@@ -639,7 +639,9 @@ END_TESTSTART_TEST (empty_input) { -QObject *obj =qobject_from_json ("" ); +const char *empty ="" ; + +QObject *obj =qobject_from_json (empty);fail_unless (obj ==NULL ); }END_TEST
Re: [Qemu-devel] [PATCH] Silence compiler warning in json test case
Quoted 13 lines · On Sat, 16 Oct 2010 19:42:43 +0200 Jan Kiszka <[email protected]> wrote:
Quoted 11 lines · Blue Swirl
Quoted 7 lines · Paolo Bonzini
Quoted 2 lines · Blue Swirl
Which functions are optimized away and which aren't?
It's builtins only that are optimized away or otherwise inlined (printf, sprintf, etc.). Other calls stay, together with side effects and clock cycles.
Then the warning makes sense (slightly) and should remain on main QEMU side.
Quoted 7 lines
From: Jan Kiszka <[email protected]>
This avoids
error: zero-length
gnu_printfformat stringSigned-off-by Jan Kiszka <[email protected]>
I've applied this one to the QMP queue, but of course that Blue can push it if he wants to.
Quoted 20 lines
--- check-qjson.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)check-qjson.c +3
-1@@ -639,7 +639,9 @@ END_TESTSTART_TEST (empty_input) { -QObject *obj =qobject_from_json ("" ); +const char *empty ="" ; + +QObject *obj =qobject_from_json (empty);fail_unless (obj ==NULL ); }END_TEST