[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openocd-development
Subject:    [OpenOCD-devel] [PATCH]: a149bea riscv: riscv-013: fix receive_addr calculation fault
From:       gerrit () openocd ! org (gerrit)
Date:       2019-09-07 15:10:05
Message-ID: 20190907151005.CD0212522570 () mail ! openocd ! org
[Download RAW message or body]

This is an automated email from Gerrit.

Icenowy Zheng (icenowy@aosc.io) just uploaded a new patch set to Gerrit, which you \
can find at http://openocd.zylin.com/5296

-- gerrit

commit a149beaa2ed04a124f5df0c90807b59fceca6048
Author: Icenowy Zheng <icenowy@aosc.io>
Date:   Sat Sep 7 14:12:13 2019 +0800

    riscv: riscv-013: fix receive_addr calculation fault
    
    When calculating the receive_addr, it substracts the loop temporary
    variable i by 2, which is an unsigned integer (size_t) starts at 0.
    
    As an unsigned integer should not be subtracted by a bigger number,
    fix this formula by preventing this substraction.
    
    This fixes wrong receive_addr when size_t is not of the same size
    as riscv_addr_t.
    
    Change-Id: I76ff8fc3f1215317eb49391e5b4923384d629dc4
    Signed-off-by: Icenowy Zheng <icenowy@aosc.io>

diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c
index 5683e5a..09ef457 100644
--- a/src/target/riscv/riscv-013.c
+++ b/src/target/riscv/riscv-013.c
@@ -2234,7 +2234,7 @@ static int read_memory_progbuf_inner(struct target *target, \
target_addr_t addres  /* Now read whatever we got out of the batch. */
 		dmi_status_t status = DMI_STATUS_SUCCESS;
 		for (size_t i = 0; i < reads; i++) {
-			riscv_addr_t receive_addr = read_addr + (i-2) * size;
+			riscv_addr_t receive_addr = read_addr + i * size - 2 * size;
 			assert(receive_addr < address + size * count);
 			if (receive_addr < address)
 				continue;

-- 


_______________________________________________
OpenOCD-devel mailing list
OpenOCD-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openocd-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic