Skip to contentSkip to conversation

acpi-build: Fix compiler warning (missing gnu_printf format attribute)

PATCH Applied Stefan Weil 2 participants 4 messages Nov 17, 2013 – Nov 20, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 acpi-build: Fix compiler warning (missing gnu_printf format attribute)

gcc 4.8.2 reports this warning when extra warnings are enabled (-Wextra):

CC m68k-softmmu/hw/m68k/mcf5206.o
hw/i386/acpi-build.c: In function ‘build_append_nameseg’:
hw/i386/acpi-build.c:294:5: error:
function might be possible candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]

     g_string_vprintf(s, format, args);
     ^

When this warning is fixed, there is a new compiler warning:

CC i386-softmmu/hw/i386/acpi-build.o
hw/i386/acpi-build.c: In function ‘build_append_notify’:
hw/i386/acpi-build.c:632:5: error:
format not a string literal and no format arguments [-Werror=format-security]

     build_append_nameseg(method, name);
     ^

This is fixed here, too.

---

Note: checkpatch.pl wrongly reports an error.

 hw/i386/acpi-build.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/i386/acpi-build.c +3 -2
index 486e705..9fff5ba 100644
@@ -285,7 +285,8 @@ static inline void build_append_array(GArray *array, GArray *val)
     g_array_append_vals(array, val->data, val->len);
 }
 
-static void build_append_nameseg(GArray *array, const char *format, ...)
+static void GCC_FMT_ATTR(2, 3)
+build_append_nameseg(GArray *array, const char *format, ...)
 {
     GString *s = g_string_new("");
     va_list args;
@@ -628,7 +629,7 @@ build_append_notify(GArray *device, const char *name,
     GArray *method = build_alloc_array();
     uint8_t op = 0x14; /* MethodOp */
 
-    build_append_nameseg(method, name);
+    build_append_nameseg(method, "%s", name);
     build_append_byte(method, 0x02); /* MethodFlags: ArgCount */
     for (i = skip; i < count; i++) {
         GArray *target = build_alloc_array();
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 8 lines · Stefan Weil

gcc 4.8.2 reports this warning when extra warnings are enabled (-Wextra):

CC m68k-softmmu/hw/m68k/mcf5206.o
hw/i386/acpi-build.c: In function ‘build_append_nameseg’:
hw/i386/acpi-build.c:294:5: error:
function might be possible candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]

     g_string_vprintf(s, format, args);
     ^

Why are you sending for-1.7 patches which fixes issues which are not present in 1.7? As far as I can see, -Wextra isn't enabled in 1.7, is it?

Thanks,

/mjt

#2 lore raw

Am 17.11.2013 21:40, schrieb Michael Tokarev:

Quoted 9 lines
Quoted 8 lines · Stefan Weil

gcc 4.8.2 reports this warning when extra warnings are enabled (-Wextra):

CC m68k-softmmu/hw/m68k/mcf5206.o
hw/i386/acpi-build.c: In function ‘build_append_nameseg’:
hw/i386/acpi-build.c:294:5: error:
function might be possible candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]

     g_string_vprintf(s, format, args);
     ^
Quoted 6 lines

Why are you sending for-1.7 patches which fixes issues which are not present in 1.7? As far as I can see, -Wextra isn't enabled in 1.7, is it?

Thanks,

/mjt

We try to use format attributes for all functions with printf like arguments.

Patch http://patchwork.ozlabs.org/patch/291873/ shows that the format attribute
not only fixes a compiler warning (which is not shown with the default settings)
but also uncovers real programming errors.

I use quite a lot of build environments (32 and 64 bit, Linux and Windows cross builds)
but there still remain more which I don't cover. With the additional format attributes
any code either is okay and compiles without warning, or it uses a wrong format string,
so my patches will break only builds which compile broken code.

I think this kind of build breakage is good and important.

Regards,
Stefan

#3 lore raw
In reply to Stefan Weil
Quoted 11 lines · Stefan Weil

gcc 4.8.2 reports this warning when extra warnings are enabled (-Wextra):

CC m68k-softmmu/hw/m68k/mcf5206.o
hw/i386/acpi-build.c: In function ‘build_append_nameseg’:
hw/i386/acpi-build.c:294:5: error:
function might be possible candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]

     g_string_vprintf(s, format, args);
     ^

When this warning is fixed, there is a new compiler warning:

Quoted 8 lines

CC i386-softmmu/hw/i386/acpi-build.o
hw/i386/acpi-build.c: In function ‘build_append_notify’:
hw/i386/acpi-build.c:632:5: error:
format not a string literal and no format arguments [-Werror=format-security]

     build_append_nameseg(method, name);
     ^

This is fixed here, too.

Thanks, applied to the trivial-patches queue.

Note this patch also triggers checkpatch.pl error:

hw/i386/acpi-build.c static inline void build_append_array(GArray *array, GArray *val) · line 289

Quoted 2 lines
hw/i386/acpi-build.c +2 -0
+static void GCC_FMT_ATTR(2, 3)
+build_append_nameseg(GArray *array, const char *format, ...)
                               ^

ERROR: need consistent spacing around '*' (ctx:WxV) #40: FILE: hw/i386/acpi-build.c:289:

It looks like checkpatch.pl needs some tweaking here, because the spacing here is really consistent, as far as I can see.

/mjt