aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Sutton <josephsutton@catalyst.net.nz>2022-10-12 15:28:15 +1300
committerAndreas Schneider <asn@cryptomilk.org>2024-02-04 11:20:16 +0100
commit8be37372097d1aa5e03b565936db7891b6180e73 (patch)
treedff9c07fc3fdba72cc437175b4279a89eae34ac1
parentfb38de9dd4a020b3ed128a018c5998c06aa27d1d (diff)
downloadcmocka-stable-1.1.tar.gz
cmocka-stable-1.1.tar.xz
cmocka-stable-1.1.zip
cmocka: Fix assert_memory_equal() displaystable-1.1
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> (backported from commit 2206c22515e788f7a43cde2162408081b3e8f6ae)
-rw-r--r--src/cmocka.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/cmocka.c b/src/cmocka.c
index 6e87d39..1ea32eb 100644
--- a/src/cmocka.c
+++ b/src/cmocka.c
@@ -1394,11 +1394,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) {
- cm_print_error("difference at offset %" PRIdS " 0x%02x 0x%02x\n",
+ cm_print_error("difference at offset %" PRIdS " 0x%02hhx 0x%02hhx\n",
i, l, r);
}
differences ++;