Patchwork mips_fulong2e: Detect format errors for function prom_set

login
register
mail settings
Submitter Stefan Weil
Date Sept. 11, 2010, 6:46 a.m.
Message ID <1284187585-20953-1-git-send-email-weil@mail.berlios.de>
Download mbox | patch
Permalink /patch/64487/
State New
Headers show

Comments

Stefan Weil - Sept. 11, 2010, 6:46 a.m.
Add the necessary gcc attribute and fix the detected errors.

Cc: Aurelien Jarno <aurelien@aurel32.net>
Signed-off-by: Stefan Weil <weil@mail.berlios.de>
---
 hw/mips_fulong2e.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
Blue Swirl - Sept. 20, 2010, 7:03 p.m.
On Sat, Sep 11, 2010 at 6:46 AM, Stefan Weil <weil@mail.berlios.de> wrote:
> Add the necessary gcc attribute and fix the detected errors.

The fixes are correct, so those parts could be applied.

However the gnu_printf part will break with older compilers unless 1/2
is applied first. That part should also use GCC_FMT_ATTR macro. Please
split the patch.

>
> Cc: Aurelien Jarno <aurelien@aurel32.net>
> Signed-off-by: Stefan Weil <weil@mail.berlios.de>
> ---
>  hw/mips_fulong2e.c |    8 +++++---
>  1 files changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/hw/mips_fulong2e.c b/hw/mips_fulong2e.c
> index cbe7156..2ef5070 100644
> --- a/hw/mips_fulong2e.c
> +++ b/hw/mips_fulong2e.c
> @@ -77,6 +77,8 @@ static struct _loaderparams {
>  } loaderparams;
>
>  static void prom_set(uint32_t* prom_buf, int index, const char *string, ...)
> +    __attribute__ ((format (gnu_printf, 3, 4)));
> +static void prom_set(uint32_t* prom_buf, int index, const char *string, ...)
>  {
>     va_list ap;
>     int32_t table_addr;
> @@ -141,13 +143,13 @@ static int64_t load_kernel (CPUState *env)
>     prom_size = ENVP_NB_ENTRIES * (sizeof(int32_t) + ENVP_ENTRY_SIZE);
>     prom_buf = qemu_malloc(prom_size);
>
> -    prom_set(prom_buf, index++, loaderparams.kernel_filename);
> +    prom_set(prom_buf, index++, "%s", loaderparams.kernel_filename);
>     if (initrd_size > 0) {
> -        prom_set(prom_buf, index++, "rd_start=0x" PRIx64 " rd_size=%li %s",
> +        prom_set(prom_buf, index++, "rd_start=0x%" PRIx64 " rd_size=%li %s",
>                  cpu_mips_phys_to_kseg0(NULL, initrd_offset), initrd_size,
>                  loaderparams.kernel_cmdline);
>     } else {
> -        prom_set(prom_buf, index++, loaderparams.kernel_cmdline);
> +        prom_set(prom_buf, index++, "%s", loaderparams.kernel_cmdline);
>     }
>
>     /* Setup minimum environment variables */
> --
> 1.7.0.4
>
>
>

Patch

diff --git a/hw/mips_fulong2e.c b/hw/mips_fulong2e.c
index cbe7156..2ef5070 100644
--- a/hw/mips_fulong2e.c
+++ b/hw/mips_fulong2e.c
@@ -77,6 +77,8 @@  static struct _loaderparams {
 } loaderparams;
 
 static void prom_set(uint32_t* prom_buf, int index, const char *string, ...)
+    __attribute__ ((format (gnu_printf, 3, 4)));
+static void prom_set(uint32_t* prom_buf, int index, const char *string, ...)
 {
     va_list ap;
     int32_t table_addr;
@@ -141,13 +143,13 @@  static int64_t load_kernel (CPUState *env)
     prom_size = ENVP_NB_ENTRIES * (sizeof(int32_t) + ENVP_ENTRY_SIZE);
     prom_buf = qemu_malloc(prom_size);
 
-    prom_set(prom_buf, index++, loaderparams.kernel_filename);
+    prom_set(prom_buf, index++, "%s", loaderparams.kernel_filename);
     if (initrd_size > 0) {
-        prom_set(prom_buf, index++, "rd_start=0x" PRIx64 " rd_size=%li %s",
+        prom_set(prom_buf, index++, "rd_start=0x%" PRIx64 " rd_size=%li %s",
                  cpu_mips_phys_to_kseg0(NULL, initrd_offset), initrd_size,
                  loaderparams.kernel_cmdline);
     } else {
-        prom_set(prom_buf, index++, loaderparams.kernel_cmdline);
+        prom_set(prom_buf, index++, "%s", loaderparams.kernel_cmdline);
     }
 
     /* Setup minimum environment variables */