summaryrefslogtreecommitdiff
path: root/apps/system
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-06-16 08:37:44 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-06-16 08:37:44 -0600
commit466e4b2be4fe900e055c0fcf8582ab5724fe2523 (patch)
treecf20a5ef070da9105c315eac1b699777123911b2 /apps/system
parent1be6a4df34582ab2c8564445355dec935678f4b2 (diff)
downloadnuttx-466e4b2be4fe900e055c0fcf8582ab5724fe2523.tar.gz
nuttx-466e4b2be4fe900e055c0fcf8582ab5724fe2523.tar.bz2
nuttx-466e4b2be4fe900e055c0fcf8582ab5724fe2523.zip
hex2bin: Fix some indexing errors
Diffstat (limited to 'apps/system')
-rw-r--r--apps/system/hex2bin/hex2bin.c55
1 files changed, 30 insertions, 25 deletions
diff --git a/apps/system/hex2bin/hex2bin.c b/apps/system/hex2bin/hex2bin.c
index 252255f8c..1de5763f1 100644
--- a/apps/system/hex2bin/hex2bin.c
+++ b/apps/system/hex2bin/hex2bin.c
@@ -338,31 +338,31 @@ static int readstream(FAR struct lib_instream_s *instream,
* Name: hex2bin_swap16 and hex2bin_swap32
****************************************************************************/
-static inline void hex2bin_swap16(FAR uint8_t *bin, int bytecount)
+static inline void hex2bin_swap16(FAR uint8_t *data, int bytecount)
{
for (; bytecount > 0; bytecount -= 2)
{
- uint8_t b0 = bin[0];
- uint8_t b1 = bin[1];
+ uint8_t b0 = data[0];
+ uint8_t b1 = data[1];
- *bin++ = b1;
- *bin++ = b0;
+ *data++ = b1;
+ *data++ = b0;
}
}
-static inline void hex2bin_swap32(FAR uint8_t *bin, int bytecount)
+static inline void hex2bin_swap32(FAR uint8_t *data, int bytecount)
{
for (; bytecount > 0; bytecount -= 4)
{
- uint8_t b0 = bin[0];
- uint8_t b1 = bin[1];
- uint8_t b2 = bin[2];
- uint8_t b3 = bin[3];
-
- *bin++ = b3;
- *bin++ = b2;
- *bin++ = b1;
- *bin++ = b0;
+ uint8_t b0 = data[0];
+ uint8_t b1 = data[1];
+ uint8_t b2 = data[2];
+ uint8_t b3 = data[3];
+
+ *data++ = b3;
+ *data++ = b2;
+ *data++ = b1;
+ *data++ = b0;
}
}
@@ -371,11 +371,11 @@ static inline void hex2bin_swap32(FAR uint8_t *bin, int bytecount)
****************************************************************************/
static inline void writedata(FAR struct lib_sostream_s *outstream,
- FAR uint8_t *bin, int bytecount)
+ FAR uint8_t *data, int bytecount)
{
for (; bytecount > 0; bytecount--)
{
- outstream->put(outstream, *bin++);
+ outstream->put(outstream, *data++);
}
}
@@ -423,6 +423,7 @@ int hex2bin(FAR struct lib_instream_s *instream,
int nbytes;
int bytecount;
uint32_t address;
+ uint32_t endaddr;
uint32_t expected;
uint16_t extension;
uint16_t address16;
@@ -550,7 +551,7 @@ int hex2bin(FAR struct lib_instream_s *instream,
/* Do the byte swap */
- hex2bin_swap16(bin, bytecount);
+ hex2bin_swap16(&bin[DATA_BINNDX], bytecount);
}
break;
@@ -565,7 +566,7 @@ int hex2bin(FAR struct lib_instream_s *instream,
/* Do the byte swap */
- hex2bin_swap32(bin, bytecount);
+ hex2bin_swap32(&bin[DATA_BINNDX], bytecount);
}
break;
@@ -579,7 +580,9 @@ int hex2bin(FAR struct lib_instream_s *instream,
/* Get and verify the full 32-bit address */
address = ((uint32_t)extension << 16) | (uint32_t)address16;
- if (address < baseaddr || (endpaddr != 0 && address >= endpaddr))
+ endaddr = address + bytecount;
+
+ if (address < baseaddr || (endpaddr != 0 && endaddr >= endpaddr))
{
hex2bin_debug("Line %d ERROR: Extended address %08lx is out of range\n",
lineno, (unsigned long)address);
@@ -602,7 +605,7 @@ int hex2bin(FAR struct lib_instream_s *instream,
/* Transfer data to the OUT stream */
- writedata(outstream, bin, bytecount);
+ writedata(outstream, &bin[DATA_BINNDX], bytecount);
}
break;
@@ -632,16 +635,17 @@ int hex2bin(FAR struct lib_instream_s *instream,
* 0.
*/
- if (bytecount != 2 || address16 != 0 || bin[1] != 0)
+ if (bytecount != 2 || address16 != 0 || bin[DATA_BINNDX+1] != 0)
{
hex2bin_debug("Line %u ERROR: Invalid segment address\n",
lineno);
hex2bin_debug(" bytecount=%d address=%04x segment=%02x%02x\n",
- bytecount, address16, bin[0], bin[1]);
+ bytecount, address16, bin[DATA_BINNDX],
+ bin[DATA_BINNDX+1]);
goto errout_with_einval;
}
- extension = (uint16_t)bin[0];
+ extension = (uint16_t)bin[DATA_BINNDX];
break;
case RECORD_START_SEGADDR: /* Start segment address record */
@@ -674,7 +678,8 @@ int hex2bin(FAR struct lib_instream_s *instream,
goto errout_with_einval;
}
- extension = (uint16_t)bin[0] << 8 | (uint16_t)bin[1];
+ extension = (uint16_t)bin[DATA_BINNDX] << 8 |
+ (uint16_t)bin[DATA_BINNDX+1];
break;
case RECORD_START_LINADDR: /* Start linear address record */