fdtdump.c: Compile error with GCC 11
Hello,
I get a compile error with GCC 11 in fdtdump.c:
In file included from fdtdump.c:14:fdtdump.c: In function ‘main’:libfdt/libfdt.h:256:28: error: array subscript ‘struct fdt_header[0]’ is partly outside array bounds of ‘unsigned char[4]’ [-Werror=array-bounds] 256 | fdth->name = cpu_to_fdt32(val); \
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~libfdt/libfdt.h:258:1: note: in expansion of macro ‘fdt_set_hdr_’
258 | fdt_set_hdr_(magic);
| ^~~~~~~~~~~~
fdtdump.c:216:31: note: while referencing ‘smagic’
216 | unsigned char smagic[FDT_MAGIC_SIZE];
| ^~~~~~
cc1: all warnings being treated as errors
Signature · 14 lines
embedded brains GmbH Herr Sebastian HUBER Dornierstr. 4 82178 Puchheim Germany email: sebastian.huber-L1vi/[email protected] phone: +49-89-18 94 741 - 16 fax: +49-89-18 94 741 - 08 Registergericht: Amtsgericht München Registernummer: HRB 157899 Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler Unsere Datenschutzerklärung finden Sie hier: https://embedded-brains.de/datenschutzerklaerung/
A message that is not in the archive (sent off-list or not yet received): db5d86de-fa1b-9d44-1188-edb81578bc00-L1vi/[email protected]
Quoted 4 lines · Sebastian Huber
Hello,
I get a compile error with GCC 11 in
fdtdump.c:
Quoted 13 lines
In file included from fdtdump.c:14:
fdtdump.c: In function ‘main’:libfdt/libfdt.h:256:28: error: array subscript ‘struct fdt_header[0]’ is partly outside array bounds of ‘unsigned char[4]’ [-Werror=array-bounds] 256 |fdth->name=cpu_to_fdt32(val); \
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~libfdt/libfdt.h:258:1: note: in expansion of macro ‘fdt_set_hdr_’ 258 |fdt_set_hdr_(magic);
| ^~~~~~~~~~~~
fdtdump.c:216:31: note: while referencing ‘smagic’
216 | unsigned char smagic[FDT_MAGIC_SIZE]; | ^~~~~~
cc1: all warnings being treated as errors
Ah, I think I see what's going wrong here. I don't have easy access to gcc 11 to test with, so can you give this draft patch a test:
From 6307635b052b55cba6970ae3fb70f33259c572a4 Mon Sep 17 00:00:00 2001
From: David Gibson <[email protected]>
Date: Wed, 6 Jan 2021 14:52:26 +1100
Subject: [PATCH] fdtdump: Fix gcc11 warning
In one place, fdtdump abuses fdt_set_magic(), passing it just a small char array instead of the full fdt header it expects. That's relying on the fact that in fact fdt_set_magic() will only actually access the first 4 bytes of the buffer.
This trips a new warning in GCC 11 - and it's entirely possible it was always UB. So, don't do that.
--- fdtdump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fdtdump.c +1 -1
@@ -217,7 +217,7 @@ int main(int argc, char *argv[])char *p = buf;char *endp = buf + len; -fdt_set_magic (smagic,FDT_MAGIC ); +fdt32_st (smagic,FDT_MAGIC );/* poor man's memmem */ while ((endp - p) >=FDT_MAGIC_SIZE ) {
Signature · 10 lines
2.29.2 -- 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
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 2 lines · David Gibson
Ah, I think I see what's going wrong here. I don't have easy access to gcc 11 to test with, so can you give this draft patch a test:
Sorry for the delay. This patch fixes the dtc build problem with GCC 11. There were no other issues.
Signature · 14 lines
embedded brains GmbH Herr Sebastian HUBER Dornierstr. 4 82178 Puchheim Germany email: sebastian.huber-L1vi/[email protected] phone: +49-89-18 94 741 - 16 fax: +49-89-18 94 741 - 08 Registergericht: Amtsgericht München Registernummer: HRB 157899 Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler Unsere Datenschutzerklärung finden Sie hier: https://embedded-brains.de/datenschutzerklaerung/
A message that is not in the archive (sent off-list or not yet received): 8822ec89-7782-7608-cae5-e62770e28771-L1vi/[email protected]
Quoted 6 lines · Sebastian Huber
Quoted 2 lines · David Gibson
Ah, I think I see what's going wrong here. I don't have easy access to gcc 11 to test with, so can you give this draft patch a test:
Sorry for the delay. This patch fixes the dtc build problem with GCC 11. There were no other issues.
Thanks, fix applied.
Quoted 1 line
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