aboutsummaryrefslogtreecommitdiff
path: root/tests/libutil/is_memory_zero.c
blob: 0d10dd88a95554384c1f855f9eeceac719e5da58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* SPDX-License-Identifier: GPL-3.0-or-later */
/*
 * is_memory_zero.c
 *
 * Copyright (C) 2021 David Oberhollenzer <goliath@infraroot.at>
 */
#include "config.h"

#include "../test.h"
#include "util.h"

int main(int argc, char **argv)
{
	unsigned char temp[1024];
	size_t i, j;
	(void)argc; (void)argv;

	memset(temp, 0, sizeof(temp));

	for (i = 0; i < sizeof(temp); ++i) {
		TEST_ASSERT(is_memory_zero(temp, i));

		for (j = 0; j < i; ++j) {
			TEST_ASSERT(is_memory_zero(temp, i));
			temp[j] = 42;
			TEST_ASSERT(!is_memory_zero(temp, i));
			temp[j] = 0;
			TEST_ASSERT(is_memory_zero(temp, i));
		}
	}

	return EXIT_SUCCESS;
}