From 22bcf1c3ea1eb2879d8f2271bb372acc8b14adda Mon Sep 17 00:00:00 2001 From: cyrozap Date: Tue, 14 Oct 2014 00:57:11 -0400 Subject: [PATCH] sim_hex: Only decrement maxlen in read_hex_string when a byte is added to the array Without this fix, the output to the buffer would be limited to maxlen/2 bytes instead of maxlen. It is obvious from the implementation that the latter behavior is the expected one, so the function has been altered to reflect that. --- simavr/sim/sim_hex.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/simavr/sim/sim_hex.c b/simavr/sim/sim_hex.c index 0c4f24f..69ef0e1 100644 --- a/simavr/sim/sim_hex.c +++ b/simavr/sim/sim_hex.c @@ -51,7 +51,7 @@ int read_hex_string(const char * src, uint8_t * buffer, int maxlen) uint8_t * dst = buffer; int ls = 0; uint8_t b = 0; - while (*src && maxlen--) { + while (*src && maxlen) { char c = *src++; switch (c) { case 'a' ... 'f': b = (b << 4) | (c - 'a' + 0xa); break; @@ -66,6 +66,7 @@ int read_hex_string(const char * src, uint8_t * buffer, int maxlen) } if (ls & 1) { *dst++ = b; b = 0; + maxlen--; } ls++; } -- 2.39.5