aboutsummaryrefslogtreecommitdiffstats
path: root/sandbox/t/helpers/malloc.c
blob: 9a732bfae86655d65dee36764754100ea2579cc7 (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
#include <stdlib.h>
#include <stdint.h>
#include <limits.h>
#include <errno.h>

int main(int argc, char **argv)
{
	unsigned long long size;
	char *ptr;

	if (argc != 2)
		abort();
	errno = 0;
	size = strtoull(argv[1], NULL, 10);
	if (errno)
		abort();
#if ULONG_MAX > SIZE_MAX
	if (size > SIZE_MAX)
		abort();
#endif

	ptr = malloc(size);
	if (!ptr)
		return 1;
	for (size_t i = 0; i < size; i += 1024)
		ptr[i] = 123;
}