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.
This commit is contained in:
logicog
2026-03-09 06:48:24 +01:00
parent 7949975191
commit ed8dc0f43c
+9 -1
View File
@@ -150,6 +150,14 @@ uint8_t atoi_hex(uint8_t idx)
h_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); return ((h_idx + 1) >> 1);
} }
@@ -707,7 +715,7 @@ void parse_bw(void)
goto err; goto err;
port = cmd_buffer[cmd_words_b[2]] - '1'; port = cmd_buffer[cmd_words_b[2]] - '1';
if (port < 0 || port > 9) if (port > 9)
goto err; goto err;
port = machine.phys_to_log_port[port]; port = machine.phys_to_log_port[port];