From: cyrozap Date: Tue, 14 Oct 2014 04:57:11 +0000 (-0400) Subject: sim_hex: Only decrement maxlen in read_hex_string when a byte is added to the array X-Git-Tag: v1.3~68^2 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=22bcf1c3ea1eb2879d8f2271bb372acc8b14adda;p=sx%2Fsimavr.git 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. --- 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++; }