Optionally memset the malloced memory

This commit is contained in:
Peter J. Holzer 2024-12-11 12:54:35 +01:00 committed by Peter J. Holzer
parent 841b95221c
commit 91b9809c27
1 changed files with 7 additions and 0 deletions

View File

@ -1,10 +1,17 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char **argv) {
size_t size = strtoul(argv[1], NULL, 0);
char *p = malloc(size);
printf("%zu bytes at %p\n", size, p);
if (argv[2]) {
unsigned char c = strtoul(argv[2], NULL, 0);
memset(p, c, size);
printf("filled with %zu %02x bytes\n", size, c);
}
sleep(10);
return 0;
}