From: Heinrich Schuchardt <heinrich.schuchardt-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
To: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Heinrich Schuchardt
<heinrich.schuchardt-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
Subject: [PATCH 1/1] dtc: fix asm_emit_data()
Date: Tue, 22 Aug 2023 13:06:27 +0200 [thread overview]
Message-ID: <20230822110627.141540-1-heinrich.schuchardt@canonical.com> (raw)
((d.len - off) >= sizeof(uint32_t)) will possibly be true if off > d.len:
sizeof(uint32_t)) is an unsigned type. The C language will convert
(d.len - off) to an unsigned type before executing the comparison.
Correct the inequality.
Change the equality for byte output to match the one for uint32_t.
Fixes: 53359016caf6 ("dtc: Use stdint.h types throughout dtc")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
---
flattree.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/flattree.c b/flattree.c
index 1bcd808..9f67104 100644
--- a/flattree.c
+++ b/flattree.c
@@ -156,12 +156,12 @@ static void asm_emit_data(void *e, struct data d)
for_each_marker_of_type(m, LABEL)
emit_offset_label(f, m->ref, m->offset);
- while ((d.len - off) >= sizeof(uint32_t)) {
+ while (d.len + sizeof(uint32_t) >= off) {
asm_emit_cell(e, dtb_ld32(d.val + off));
off += sizeof(uint32_t);
}
- while ((d.len - off) >= 1) {
+ while (d.len + 1 >= off) {
fprintf(f, "\t.byte\t0x%hhx\n", d.val[off]);
off += 1;
}
--
2.40.1
next reply other threads:[~2023-08-22 11:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-22 11:06 Heinrich Schuchardt [this message]
[not found] ` <20230822110627.141540-1-heinrich.schuchardt-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
2023-08-24 5:15 ` [PATCH 1/1] dtc: fix asm_emit_data() 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=20230822110627.141540-1-heinrich.schuchardt@canonical.com \
--to=heinrich.schuchardt-z7wlfzj8ewms+fvcfc7uqw@public.gmane.org \
--cc=david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org \
--cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@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 read-only IMAP folder(s) and NNTP newsgroup(s).