From 23b53726f3c5c283112110468ff1c9b4981260e9 Mon Sep 17 00:00:00 2001 From: Alain Mosnier Date: Sat, 28 Jul 2018 16:53:38 +0200 Subject: [PATCH] Added explicit cast to correct printf() related bug --- test.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test.c b/test.c index aef78a6..feae6be 100644 --- a/test.c +++ b/test.c @@ -175,13 +175,20 @@ static int string_test(const char input[], const char output[]) } } +/* + * Limitation: + * - The variable input_len will be truncated to its LONG_BIT least + * significant bits in the print output. This will never be a problem + * for values that in practice are less than 2^32 - 1. Rationale: ANSI + * C-compatibility and keeping it simple. + */ static int test(const uint8_t * input, size_t input_len, const char output[]) { uint8_t hash[32]; char hash_string[65]; calc_sha_256(hash, input, input_len); hash_to_string(hash_string, hash); - printf("input starts with 0x%02x, length %lu\n", *input, input_len); + printf("input starts with 0x%02x, length %lu\n", *input, (unsigned long) input_len); printf("hash : %s\n", hash_string); if (strcmp(output, hash_string)) { printf("FAILURE!\n\n");