Mercurial > hg > index.cgi
changeset 425:9f0448022f1f
Fix address overflows in SREC and IHEX file formats
Thanks to hider <stego@satx.rr.com> for pointing out an overflow that caused
16 bit addresses to be output as 5 hex digits in cases where an address
counter wrapped. Simply mask the addresses down to 16 bits.
author | William Astle <lost@l-w.ca> |
---|---|
date | Thu, 03 Nov 2016 21:36:17 -0600 |
parents | 3aad0ff3c3be |
children | b4825b42c151 |
files | lwasm/output.c lwlink/output.c |
diffstat | 2 files changed, 7 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/lwasm/output.c Thu Sep 22 19:26:04 2016 -0600 +++ b/lwasm/output.c Thu Nov 03 21:36:17 2016 -0600 @@ -396,7 +396,7 @@ // if address jump or xxx0 address, start new line if ((rc == -1) || ((rc == 1) && (outaddr % RECLEN == 0))) { - fprintf(of, "\r\n%04X:", (unsigned int)outaddr); + fprintf(of, "\r\n%04X:", (unsigned int)(outaddr & 0xffff)); fprintf(of, "%02X", (unsigned char)outbyte); rc = -1; } @@ -459,7 +459,7 @@ if (recdlen > 0) { recsum = recdlen + 3; - fprintf(of, "S1%02X%04X", recdlen + 3, recaddr); + fprintf(of, "S1%02X%04X", recdlen + 3, recaddr & 0xffff); for (i = 0; i < recdlen; i++) { fprintf(of, "%02X", (unsigned char)recdata[i]); @@ -487,7 +487,7 @@ if (recdlen > 0) { recsum = recdlen + 3; - fprintf(of, "S1%02X%04X", recdlen + 3, recaddr); + fprintf(of, "S1%02X%04X", recdlen + 3, recaddr & 0xffff); for (i = 0; i < recdlen; i++) { fprintf(of, "%02X", (unsigned char)recdata[i]); @@ -513,7 +513,7 @@ recsum = 3; recsum += (as -> execaddr >> 8) & 0xFF; recsum += (as -> execaddr) & 0xFF; - fprintf(of, "S903%04X", as -> execaddr); + fprintf(of, "S903%04X", as -> execaddr & 0xffff); fprintf(of, "%02X\r\n", (unsigned char)(~recsum)); } } @@ -548,7 +548,7 @@ if (recdlen > 0) { recsum = recdlen; - fprintf(of, ":%02X%04X00", recdlen, recaddr); + fprintf(of, ":%02X%04X00", recdlen, recaddr & 0xffff); for (i = 0; i < recdlen; i++) { fprintf(of, "%02X", (unsigned char)recdata[i]); @@ -576,7 +576,7 @@ if (recdlen > 0) { recsum = recdlen; - fprintf(of, ":%02X%04X00", recdlen, recaddr); + fprintf(of, ":%02X%04X00", recdlen, recaddr & 0xffff); for (i = 0; i < recdlen; i++) { fprintf(of, "%02X", (unsigned char)recdata[i]);
--- a/lwlink/output.c Thu Sep 22 19:26:04 2016 -0600 +++ b/lwlink/output.c Thu Nov 03 21:36:17 2016 -0600 @@ -198,7 +198,7 @@ recdlen = (SRECLEN>remainingcodebytes)?remainingcodebytes:SRECLEN; recsum = recdlen + 3; codeaddr = recaddr - sectlist[sn].ptr -> loadaddress; - fprintf(of, "S1%02X%04X", recdlen + 3, recaddr); + fprintf(of, "S1%02X%04X", recdlen + 3, recaddr & 0xffff); for (i = 0; i < recdlen; i++) { fprintf(of, "%02X", sectcode[codeaddr+i]);