cmocka: Fix assert_memory_equal() display

The %x specifier expects an unsigned argument. If char is signed,
cmocka_print_error() may incorrectly display values sign-extended. To
fix this, use an unsigned char and the corresponding format specifier
(%hhx).

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Joseph Sutton 2022-10-12 15:28:15 +13:00 committed by Andreas Schneider
parent 90315882d6
commit 2206c22515
1 changed files with 3 additions and 3 deletions

View File

@ -1646,11 +1646,11 @@ static int memory_equal_display_error(const char* const a, const char* const b,
size_t differences = 0;
size_t i;
for (i = 0; i < size; i++) {
const char l = a[i];
const char r = b[i];
const unsigned char l = a[i];
const unsigned char r = b[i];
if (l != r) {
if (differences < 16) {
cmocka_print_error("difference at offset %" PRIdS " 0x%02x 0x%02x\n",
cmocka_print_error("difference at offset %" PRIdS " 0x%02hhx 0x%02hhx\n",
i, l, r);
}
differences ++;