target/riscv: Fix build errors
PATCH 1/1 target/riscv: Fix build errors
Newer gcc compiler (version 16.0.0 20260103 (Red Hat 16.0.0-0) (GCC)) detects a truncation error:
../target/riscv/cpu.c: In function ‘riscv_isa_write_fdt’:
../target/riscv/cpu.c:2916:35: error: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 5 [-Werror=format-truncation=]
2916 | snprintf(isa_base, maxlen, "rv%di", xlen);
| ^~
../target/riscv/cpu.c:2916:32: note: directive argument in the range [-2147483648, 2147483632]
2916 | snprintf(isa_base, maxlen, "rv%di", xlen);
| ^~~~~~~
Since the xlen variable represents the register width (32, 64, 128) in the RISC-V base ISA name, mask its value with a 8-bit bitmask to satisfy the size constraints on the snprintf output.
--- target/riscv/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/cpu.c +1 -1
@@ -2913,7 +2913,7 @@ void riscv_isa_write_fdt(RISCVCPU *cpu, void *fdt, char *nodename) riscv_isa =riscv_isa_string (cpu);qemu_fdt_setprop_string (fdt, nodename,"riscv,isa" , riscv_isa); -snprintf (isa_base, maxlen,"rv%di" , xlen); +snprintf (isa_base, maxlen,"rv%di" , xlen &0xFF );qemu_fdt_setprop_string (fdt, nodename,"riscv,isa-base" , isa_base); isa_extensions =riscv_isa_extensions_list (cpu, &count);
Signature · 1 line
2.52.0
Quoted 15 lines · Cédric Le Goater
Newer gcc compiler (version 16.0.0 20260103 (Red Hat 16.0.0-0) (GCC)) detects a truncation error:
../target/riscv/cpu.c: In function ‘riscv_isa_write_fdt’:
../target/riscv/cpu.c:2916:35: error: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 5 [-Werror=format-truncation=]2916 | snprintf(isa_base, maxlen, "rv%di", xlen); | ^~ ../target/riscv/cpu.c:2916:32: note: directive argument in the range [-2147483648, 2147483632] 2916 | snprintf(isa_base, maxlen, "rv%di", xlen); | ^~~~~~~Since the xlen variable represents the register width (32, 64, 128) in the RISC-V base ISA name, mask its value with a 8-bit bitmask to satisfy the size constraints on the snprintf output.
Quoted 7 lines
Cc Palmer Dabbelt <[email protected]>Cc Alistair Francis <[email protected]>Cc Weiwei Li <[email protected]>Cc Daniel Henrique Barboza <[email protected]>Cc Liu Zhiwei <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>---
Quoted 16 lines
target/riscv/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/riscv/cpu.c +1
-1@@ -2913,7 +2913,7 @@ void riscv_isa_write_fdt(RISCVCPU *cpu, void *fdt, char *nodename) riscv_isa =riscv_isa_string (cpu);qemu_fdt_setprop_string (fdt, nodename,"riscv,isa" , riscv_isa); -snprintf (isa_base, maxlen,"rv%di" , xlen); +snprintf (isa_base, maxlen,"rv%di" , xlen &0xFF );qemu_fdt_setprop_string (fdt, nodename,"riscv,isa-base" , isa_base); isa_extensions =riscv_isa_extensions_list (cpu, &count);
Cédric Le Goater
AppliedQuoted 30 lines · Cédric Le Goater
Newer gcc compiler (version 16.0.0 20260103 (Red Hat 16.0.0-0) (GCC)) detects a truncation error:
../target/riscv/cpu.c: In function ‘riscv_isa_write_fdt’:
../target/riscv/cpu.c:2916:35: error: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 5 [-Werror=format-truncation=]2916 | snprintf(isa_base, maxlen, "rv%di", xlen); | ^~ ../target/riscv/cpu.c:2916:32: note: directive argument in the range [-2147483648, 2147483632] 2916 | snprintf(isa_base, maxlen, "rv%di", xlen); | ^~~~~~~Since the xlen variable represents the register width (32, 64, 128) in the RISC-V base ISA name, mask its value with a 8-bit bitmask to satisfy the size constraints on the snprintf output.
Cc Palmer Dabbelt <[email protected]>Cc Alistair Francis <[email protected]>Cc Weiwei Li <[email protected]>Cc Daniel Henrique Barboza <[email protected]>Cc Liu Zhiwei <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>--- target/riscv/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/riscv/cpu.c +0
-0
target/riscv/cpu.c void riscv_isa_write_fdt(RISCVCPU *cpu, void *fdt, char *nodename) · line 2919
Quoted 8 lines
target/riscv/cpu.c +1
-1@@ -2913,7 +2913,7 @@ void riscv_isa_write_fdt(RISCVCPU *cpu, void *fdt, char *nodename) riscv_isa =riscv_isa_string (cpu);qemu_fdt_setprop_string (fdt, nodename,"riscv,isa" , riscv_isa); -snprintf (isa_base, maxlen,"rv%di" , xlen); +snprintf (isa_base, maxlen,"rv%di" , xlen &0xFF );qemu_fdt_setprop_string (fdt, nodename,"riscv,isa-base" , isa_base); isa_extensions =riscv_isa_extensions_list (cpu, &count);
Applied to vfio-next.
Thanks,
C.