Patchwork Avoid issue with pp-directive in macro

login
register
mail settings
Submitter Bruce Rogers
Date Aug. 7, 2009, 10:15 p.m.
Message ID <4A7C531A020000480007DF91@lucius.provo.novell.com>
Download mbox | patch
Permalink /patch/30988/
State Superseded
Headers show

Comments

Bruce Rogers - Aug. 7, 2009, 10:15 p.m.
When building for SLES10, I ran into a build failure which results from printf being a macro, and two files which have an #include preprocessing directive within the macro arguments.  There are other pp-directives,but the #include was the only one causing problems.  (This was with gcc 4.x btw.)

It is undefined behavior to include pp-directives within macro arguments, and pretty much any of the std-c defined functions can be implemented as macros, so this patch avoids the issue by ensuring we are not using the macro version in the problematic cases.

Signed-off-by: Bruce Rogers <brogers@novell.com>

 qemu-img.c |    2 +-
 vl.c       |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Anthony Liguori - Aug. 8, 2009, 1:44 a.m.
Bruce Rogers wrote:
> When building for SLES10, I ran into a build failure which results from printf being a macro, and two files which have an #include preprocessing directive within the macro arguments.  There are other pp-directives,but the #include was the only one causing problems.  (This was with gcc 4.x btw.)
>
> It is undefined behavior to include pp-directives within macro arguments, and pretty much any of the std-c defined functions can be implemented as macros, so this patch avoids the issue by ensuring we are not using the macro version in the problematic cases.
>
> Signed-off-by: Bruce Rogers <brogers@novell.com>
>   

I'd rather just use a %s.  (printf) looks odd.

Regards,

Anthony Liguori

Patch

diff --git a/qemu-img.c b/qemu-img.c
index 070fe2e..581a908 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -58,7 +58,7 @@  static void format_print(void *opaque, const char *name)
 /* Please keep in synch with qemu-img.texi */
 static void help(void)
 {
-    printf("qemu-img version " QEMU_VERSION ", Copyright (c) 2004-2008 Fabrice Bellard\n"
+    (printf)("qemu-img version " QEMU_VERSION ", Copyright (c) 2004-2008 Fabrice Bellard\n"
            "usage: qemu-img command [command options]\n"
            "QEMU disk image utility\n"
            "\n"
diff --git a/vl.c b/vl.c
index fdd4f03..0bea27f 100644
--- a/vl.c
+++ b/vl.c
@@ -4337,7 +4337,7 @@  static void version(void)
 static void help(int exitcode)
 {
     version();
-    printf("usage: %s [options] [disk_image]\n"
+    (printf)("usage: %s [options] [disk_image]\n"
            "\n"
            "'disk_image' is a raw hard image image for IDE hard disk 0\n"
            "\n"