Re: fdtdump.c: Compile error with GCC 11

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



On Mon, Jan 04, 2021 at 09:39:00AM +0100, Sebastian Huber wrote:
> 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

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 <david@xxxxxxxxxxxxxxxxxxxxx>
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.

Signed-off-by: David Gibson <david@xxxxxxxxxxxxxxxxxxxxx>
---
 fdtdump.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fdtdump.c b/fdtdump.c
index 9613bef..d9fb374 100644
--- a/fdtdump.c
+++ b/fdtdump.c
@@ -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) {
-- 
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

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Device Tree]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux