Skip to content
Snippets Groups Projects
Commit 254a6e69 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

tests/cksum_verify.c: release allocated memory.

parent ab4b4ac7
No related branches found
No related tags found
No related merge requests found
Pipeline #19662 failed
......@@ -20,14 +20,17 @@ enum {
int
main()
{
unsigned char *test_data, *init_block;
unsigned char *test_data = NULL, *init_block = NULL;
size_t num_blocks = 1000;
if (!(init_block = (unsigned char *)calloc(block_size * block_size, 1U))
|| !(test_data = (unsigned char *)calloc((size_t)block_size * num_blocks, 1U)))
return EXIT_FAILURE;
/* this is supposed to be non-random */
srand48(5L);
init_block[7] = 15U;
/* repeat block and rotate */
for (size_t i = 1; i < block_size; ++i)
{
......@@ -36,18 +39,24 @@ main()
memcpy(init_block + block_size * i + i, init_block,
block_size - i);
}
for (size_t i = 0; i < num_blocks; ++i)
{
size_t block_idx = ((size_t)lrand48()) % block_size;
memcpy(test_data + i, init_block + block_idx * block_size,
block_size);
}
uint32_t cksum_result = memcrc(test_data, num_blocks * block_size);
if (cksum_result != UINT32_C(0xc47779cd))
{
printf("unexpected crc result: 0x%8" PRIx32"\n", cksum_result);
return EXIT_FAILURE;
}
if (test_data) free(test_data);
if (init_block) free(init_block);
return EXIT_SUCCESS;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment