1
0
mirror of https://gitlab.com/80486DX2-66/gists synced 2024-12-25 17:19:46 +05:30

safe_mem.test.c: enhance macro DUMP_INT_ARRAY for multiple scenarios

This commit is contained in:
Intel A80486DX2-66 2024-06-26 11:57:03 +03:00
parent f14e505673
commit 269c1dec27
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B

View File

@ -18,10 +18,10 @@
#define PRINT_POINTER(caption, ptr) \
printf(caption " = %p\n", (void*) ptr);
#define DUMP_INT_ARRAY(caption, ptr, count) do { \
#define DUMP_INT_ARRAY(caption, ptr, count, fmt) do { \
printf("%s: [", caption); \
for (size_t i = 0; i < count; i++) { \
printf("%d", ptr[i]); \
printf(fmt, ptr[i]); \
if (i != (count - 1)) \
printf(", "); \
} \
@ -37,7 +37,8 @@ int main(void) {
integers[1] = EOF;
integers[2] = 2;
integers[3] = 1;
DUMP_INT_ARRAY("int* integers (before secure erasure)", integers, COUNT);
DUMP_INT_ARRAY("int* integers (before secure erasure)", integers, COUNT,
"%d");
printf("Secure erasure is "
#if NO_SECURE_ERASE_WARRANTY
"not guaranteed!"
@ -51,7 +52,8 @@ int main(void) {
);
secure_erase(integers, COUNT * sizeof(int));
DUMP_INT_ARRAY("int* integers (after secure erasure)", integers, COUNT);
DUMP_INT_ARRAY("int* integers (after secure erasure)", integers, COUNT,
"%d");
safe_free(integers);
PRINT_POINTER("int* integers (after freeing)", integers);