Added explicit cast to correct printf() related bug

This commit is contained in:
Alain Mosnier 2018-07-28 16:53:38 +02:00
parent f03474231f
commit 23b53726f3
1 changed files with 8 additions and 1 deletions

9
test.c
View File

@ -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[]) static int test(const uint8_t * input, size_t input_len, const char output[])
{ {
uint8_t hash[32]; uint8_t hash[32];
char hash_string[65]; char hash_string[65];
calc_sha_256(hash, input, input_len); calc_sha_256(hash, input, input_len);
hash_to_string(hash_string, hash); 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); printf("hash : %s\n", hash_string);
if (strcmp(output, hash_string)) { if (strcmp(output, hash_string)) {
printf("FAILURE!\n\n"); printf("FAILURE!\n\n");