mirror of
https://github.com/GrapheneOS/hardened_malloc.git
synced 2025-04-19 22:10:19 +02:00
C23 declared calling realloc(3) with a non-NULL pointer and zero size Undefined behavior. Check that hardened_malloc handles that case sanely by free'ing the old pointer and returning a special pointer, like `malloc(3)` called with size zero.
21 lines
257 B
C
21 lines
257 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "test_util.h"
|
|
|
|
OPTNONE int main(void) {
|
|
char *p, *q, *r;
|
|
|
|
p = malloc(256 * 1024);
|
|
if (!p) {
|
|
return 1;
|
|
}
|
|
|
|
q = realloc(p, 0);
|
|
|
|
printf("%c\n", *p);
|
|
|
|
free(q);
|
|
|
|
return 0;
|
|
}
|