From 644ae0749865ceff02861d474a5b9ad319a316bd Mon Sep 17 00:00:00 2001 From: Leandre Gohy Date: Thu, 19 Nov 2020 11:23:51 +0100 Subject: [PATCH] eepmake: Fix parse_data sscanf `%2X` format string reads `sizeof(int)` bytes, but only 2 hexadecimal characters are supplied by `c` pointer which is 1 byte long. Using `%2hhX` tells sscanf to read sizeof(char) bytes or 1 byte. On system where sizeof(int) == sizeof(char) this is no issue but on other ones, the arithmetic operation `(unsigned int*)*data+data_len++` is increasing the pointer sizeof(int) bytes instead instead of 1 byte. --- eepromutils/eepmake.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eepromutils/eepmake.c b/eepromutils/eepmake.c index 8cd5369..33a4132 100644 --- a/eepromutils/eepmake.c +++ b/eepromutils/eepmake.c @@ -155,7 +155,7 @@ void parse_data(char* c) { *data = (char *) realloc(*data, data_cap); } - sscanf(c, "%2x", (unsigned int *)*data+data_len++); + sscanf(c, "%2hhX", (unsigned char *)*data+data_len++); *(c+2) = s; c+=2;