From: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
To: Sebastian Huber
<sebastian.huber-L1vi/lXTdtsBbLBgBO8hYIQuADTiUCJX@public.gmane.org>
Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: fdtdump.c: Compile error with GCC 11
Date: Wed, 6 Jan 2021 14:54:31 +1100 [thread overview]
Message-ID: <20210106035431.GB3209@yekko.fritz.box> (raw)
In-Reply-To: <db5d86de-fa1b-9d44-1188-edb81578bc00-L1vi/lXTdtsBbLBgBO8hYIQuADTiUCJX@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 2385 bytes --]
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-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
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-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
---
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 #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2021-01-06 3:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-04 8:39 fdtdump.c: Compile error with GCC 11 Sebastian Huber
[not found] ` <db5d86de-fa1b-9d44-1188-edb81578bc00-L1vi/lXTdtsBbLBgBO8hYIQuADTiUCJX@public.gmane.org>
2021-01-06 3:54 ` David Gibson [this message]
[not found] ` <20210106035431.GB3209-l+x2Y8Cxqc4e6aEkudXLsA@public.gmane.org>
2021-01-15 5:22 ` Sebastian Huber
[not found] ` <8822ec89-7782-7608-cae5-e62770e28771-L1vi/lXTdtsBbLBgBO8hYIQuADTiUCJX@public.gmane.org>
2021-01-18 6:50 ` David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210106035431.GB3209@yekko.fritz.box \
--to=david-xt8fgy+axnrb3ne2bgzf6laj5h9x9tb+@public.gmane.org \
--cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=sebastian.huber-L1vi/lXTdtsBbLBgBO8hYIQuADTiUCJX@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).