diff options
Diffstat (limited to 'sandbox/t/helpers/malloc.c')
-rw-r--r-- | sandbox/t/helpers/malloc.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/sandbox/t/helpers/malloc.c b/sandbox/t/helpers/malloc.c new file mode 100644 index 0000000..9a732bf --- /dev/null +++ b/sandbox/t/helpers/malloc.c @@ -0,0 +1,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; +} |