devicetree-compiler.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] dtc: fix asm_emit_data()
@ 2023-08-22 11:06 Heinrich Schuchardt
       [not found] ` <20230822110627.141540-1-heinrich.schuchardt-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Heinrich Schuchardt @ 2023-08-22 11:06 UTC (permalink / raw)
  To: David Gibson
  Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA, Heinrich Schuchardt

((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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-08-24  5:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-22 11:06 [PATCH 1/1] dtc: fix asm_emit_data() Heinrich Schuchardt
     [not found] ` <20230822110627.141540-1-heinrich.schuchardt-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
2023-08-24  5:15   ` David Gibson

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).