Fix bug reading hex values

This commit is contained in:
Simon Gellis 2024-10-01 22:01:36 -04:00
parent 42396701e0
commit e320dc59f4
1 changed files with 3 additions and 3 deletions

6
main.c
View File

@ -114,11 +114,11 @@ bool read_hex_byte(char *buf, char *val) {
bool read_hex_i32(char *buf, int32_t *val) {
char byte;
*val = 0;
for (int i = 0; i < 8; i += 2) {
if (!read_hex_byte(buf + i, &byte)) {
for (int i = 0; i < 4; ++i) {
if (!read_hex_byte(buf + (i * 2), &byte)) {
return false;
}
*val |= ((int32_t) (uint8_t) byte) << i;
*val |= ((int32_t) (uint8_t) byte) << (i * 8);
}
return true;
}