From ed8dc0f43c6f37d62164a44e6573fc7a111a11b9 Mon Sep 17 00:00:00 2001 From: logicog Date: Mon, 9 Mar 2026 06:46:50 +0100 Subject: [PATCH] Fix bug in atoi_hex when uneven number of digits parsed We fix a bug in atoi_hex when parsing an unneven number of digits by rotating the entire number 4 bits right as would have been done if the number had been preceded by a 0 to make the number of digits even. --- cmd_parser.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd_parser.c b/cmd_parser.c index e359513..8b03c49 100644 --- a/cmd_parser.c +++ b/cmd_parser.c @@ -150,6 +150,14 @@ uint8_t atoi_hex(uint8_t idx) h_idx++; } + if (h_idx & 1) { + hexvalue[h_idx >> 1] <<= 4; + hexvalue[3] = hexvalue[3] >> 4 | (hexvalue[2] << 4); + hexvalue[2] = hexvalue[2] >> 4 | (hexvalue[1] << 4); + hexvalue[1] = hexvalue[1] >> 4 | (hexvalue[0] << 4); + hexvalue[0] >>= 4; + } + return ((h_idx + 1) >> 1); } @@ -707,7 +715,7 @@ void parse_bw(void) goto err; port = cmd_buffer[cmd_words_b[2]] - '1'; - if (port < 0 || port > 9) + if (port > 9) goto err; port = machine.phys_to_log_port[port];