exynos4210_gic: Suppress gcc9 format-truncation warnings
PATCH 1/1 exynos4210_gic: Suppress gcc9 format-truncation warnings
exynos4210_gic_realize() prints the number of cpus into some temporary buffers, but it only allows 3 bytes space for it. That's plenty - I'm pretty sure that existing machines will only ever set this value to 2 (EXYNOS4210_NCPUS). But the compiler can't really be expected to figure that out.
Some[*] gcc9 versions therefore emit -Wformat-truncation warnings. Fix that by allowing more space in the temporary buffers - these are on stack very briefly before being essentially strdup()ed inside the memory region code, so there's not much cost to doing so.
[*] The bizarre thing here, is that I've long gotten these warnings compiling in a 32-bit x86 container as host - Fedora 30 with gcc-9.2.1-1.fc30.i686 - but it compiles just fine on my normal x86_64 host
- Fedora 30 with and gcc-9.2.1-1.fc30.x86_64.
--- hw/intc/exynos4210_gic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/intc/exynos4210_gic.c +2 -2
@@ -290,8 +290,8 @@ static void exynos4210_gic_realize(DeviceState *dev, Error **errp)SysBusDevice *sbd =SYS_BUS_DEVICE (obj);const char cpu_prefix[] ="exynos4210-gic-alias_cpu" ;const char dist_prefix[] ="exynos4210-gic-alias_dist" ; -char cpu_alias_name[sizeof (cpu_prefix) +3 ]; -char dist_alias_name[sizeof (cpu_prefix) +3 ]; +char cpu_alias_name[sizeof (cpu_prefix) +10 ]; +char dist_alias_name[sizeof (cpu_prefix) +10 ];SysBusDevice *gicbusdev;uint32_t i;
Signature · 1 line
2.21.0
Quoted 26 lines · David Gibson
exynos4210_gic_realize()prints the number of cpus into some temporary buffers, but it only allows 3 bytes space for it. That's plenty - I'm pretty sure that existing machines will only ever set this value to 2 (EXYNOS4210_NCPUS). But the compiler can't really be expected to figure that out.Some[*] gcc9 versions therefore emit -Wformat-truncation warnings. Fix that by allowing more space in the temporary buffers - these are on stack very briefly before being essentially strdup()ed inside the memory region code, so there's not much cost to doing so.
[*] The bizarre thing here, is that I've long gotten these warnings compiling in a 32-bit x86 container as host - Fedora 30 with gcc-9.2.1-1.fc30.i686 - but it compiles just fine on my normal
x86_64host
- Fedora 30 with and gcc-9.2.1-1.fc30.x86_64.Signed-off-by David Gibson <[email protected]>--- hw/intc/exynos4210_gic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/intc/exynos4210_gic.c +0
-0
hw/intc/exynos4210_gic.c static void exynos4210_gic_realize(DeviceState *dev, Error **errp) · line 294
Quoted 7 lines
hw/intc/exynos4210_gic.c +2
-2@@ -290,8 +290,8 @@ static void exynos4210_gic_realize(DeviceState *dev, Error **errp)SysBusDevice *sbd =SYS_BUS_DEVICE (obj);const char cpu_prefix[] ="exynos4210-gic-alias_cpu" ;const char dist_prefix[] ="exynos4210-gic-alias_dist" ; -char cpu_alias_name[sizeof (cpu_prefix) +3 ]; -char dist_alias_name[sizeof (cpu_prefix) +3 ]; +char cpu_alias_name[sizeof (cpu_prefix) +10 ]; +char dist_alias_name[sizeof (cpu_prefix) +10 ];
Hmm magic again... So GCC provides a new warning with no helpful definitions about how to clean this :(
We already have:
#define UUID_FMT_LEN 36
What about adding/using UINT32_FMT_LEN?
Quoted 4 lines
hw/intc/exynos4210_gic.c +0
-0SysBusDevice *gicbusdev;uint32_t i;
Quoted 27 lines · David Gibson
exynos4210_gic_realize()prints the number of cpus into some temporary buffers, but it only allows 3 bytes space for it. That's plenty - I'm pretty sure that existing machines will only ever set this value to 2 (EXYNOS4210_NCPUS). But the compiler can't really be expected to figure that out.Some[*] gcc9 versions therefore emit -Wformat-truncation warnings. Fix that by allowing more space in the temporary buffers - these are on stack very briefly before being essentially strdup()ed inside the memory region code, so there's not much cost to doing so.
[*] The bizarre thing here, is that I've long gotten these warnings compiling in a 32-bit x86 container as host - Fedora 30 with gcc-9.2.1-1.fc30.i686 - but it compiles just fine on my normal
x86_64host
- Fedora 30 with and gcc-9.2.1-1.fc30.x86_64.Signed-off-by David Gibson <[email protected]>--- hw/intc/exynos4210_gic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/intc/exynos4210_gic.c +0
-0
hw/intc/exynos4210_gic.c static void exynos4210_gic_realize(DeviceState *dev, Error **errp) · line 296
Quoted 9 lines
hw/intc/exynos4210_gic.c +2
-2@@ -290,8 +290,8 @@ static void exynos4210_gic_realize(DeviceState *dev, Error **errp)SysBusDevice *sbd =SYS_BUS_DEVICE (obj);const char cpu_prefix[] ="exynos4210-gic-alias_cpu" ;const char dist_prefix[] ="exynos4210-gic-alias_dist" ; -char cpu_alias_name[sizeof (cpu_prefix) +3 ]; -char dist_alias_name[sizeof (cpu_prefix) +3 ]; +char cpu_alias_name[sizeof (cpu_prefix) +10 ]; +char dist_alias_name[sizeof (cpu_prefix) +10 ];SysBusDevice *gicbusdev;uint32_t i;
If we assert() that num_cpu is always <= EXYNOS4210_NCPUS is that sufficient to clue gcc in that the buffer can't overflow?
thanks
-- PMM
Quoted 32 lines · Peter Maydell
Quoted 31 lines · David Gibson
exynos4210_gic_realize()prints the number of cpus into some temporary buffers, but it only allows 3 bytes space for it. That's plenty - I'm pretty sure that existing machines will only ever set this value to 2 (EXYNOS4210_NCPUS). But the compiler can't really be expected to figure that out.Some[*] gcc9 versions therefore emit -Wformat-truncation warnings. Fix that by allowing more space in the temporary buffers - these are on stack very briefly before being essentially strdup()ed inside the memory region code, so there's not much cost to doing so.
[*] The bizarre thing here, is that I've long gotten these warnings compiling in a 32-bit x86 container as host - Fedora 30 with gcc-9.2.1-1.fc30.i686 - but it compiles just fine on my normal
x86_64host
- Fedora 30 with and gcc-9.2.1-1.fc30.x86_64.Signed-off-by David Gibson <[email protected]>--- hw/intc/exynos4210_gic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/intc/exynos4210_gic.c +0
-1@@ -290,8 +290,8 @@ static void exynos4210_gic_realize(DeviceState *dev, Error **errp)SysBusDevice *sbd =SYS_BUS_DEVICE (obj);const char cpu_prefix[] ="exynos4210-gic-alias_cpu" ;const char dist_prefix[] ="exynos4210-gic-alias_dist" ; -char cpu_alias_name[sizeof (cpu_prefix) +3 ];
Quoted 8 lines
hw/intc/exynos4210_gic.c static void exynos4210_gic_realize(DeviceState *dev, Error **errp) · line 296
Quoted 5 lines
hw/intc/exynos4210_gic.c +2
-1-char dist_alias_name[sizeof (cpu_prefix) +3 ]; +char cpu_alias_name[sizeof (cpu_prefix) +10 ]; +char dist_alias_name[sizeof (cpu_prefix) +10 ];SysBusDevice *gicbusdev;uint32_t i;If we
assert()thatnum_cpuis always <=EXYNOS4210_NCPUSis that sufficient to clue gcc in that the buffer can't overflow?
Interestingly, assert(s->num_cpu <= EXYNOS$210_NCPUS) is *not* sufficient, but assert(i <= EXYNOS4210_NCPUS) within the loop *is* enough. I've updated my patch accordingly.
This isn't 4.2 material, obviously. Should I just sit on it until 5.0 opens, or does one of you have someplace to stage the patch in the meanwhile?
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 5 lines · David Gibson
Quoted 2 lines · Peter Maydell
If we
assert()thatnum_cpuis always <=EXYNOS4210_NCPUSis that sufficient to clue gcc in that the buffer can't overflow?
Quoted 7 lines
Interestingly,
assert(s->num_cpu <= EXYNOS$210_NCPUS)is *not* sufficient, butassert(i <= EXYNOS4210_NCPUS)within the loop *is* enough. I've updated my patch accordingly.This isn't 4.2 material, obviously. Should I just sit on it until 5.0 opens, or does one of you have someplace to stage the patch in the meanwhile?
Easy fixes for compiler warnings aren't inherently out of scope for 4.2. I'm also collecting stuff for 5.0 anyway so I suggest you just send the patch.
-- PMM
Quoted 10 lines · Peter Maydell
Quoted 9 lines · David Gibson
Quoted 2 lines · Peter Maydell
If we
assert()thatnum_cpuis always <=EXYNOS4210_NCPUSis that sufficient to clue gcc in that the buffer can't overflow?Interestingly,
assert(s->num_cpu <= EXYNOS$210_NCPUS)is *not* sufficient, butassert(i <= EXYNOS4210_NCPUS)within the loop *is* enough. I've updated my patch accordingly.
Quoted 7 lines
Quoted 3 lines
This isn't 4.2 material, obviously. Should I just sit on it until 5.0 opens, or does one of you have someplace to stage the patch in the meanwhile?
Easy fixes for compiler warnings aren't inherently out of scope for 4.2. I'm also collecting stuff for 5.0 anyway so I suggest you just send the patch.
Ok, done.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson