malloc-interprocedural.c [plain text]
#include "Inputs/system-header-simulator.h"
void *malloc(size_t);
void *valloc(size_t);
void free(void *);
void *realloc(void *ptr, size_t size);
void *reallocf(void *ptr, size_t size);
void *calloc(size_t nmemb, size_t size);
void exit(int) __attribute__ ((__noreturn__));
void *memcpy(void * restrict s1, const void * restrict s2, size_t n);
size_t strlen(const char *);
static void my_malloc1(void **d, size_t size) {
*d = malloc(size);
}
static void *my_malloc2(int elevel, size_t size) {
void *data;
data = malloc(size);
if (data == 0)
exit(0);
return data;
}
static void my_free1(void *p) {
free(p);
}
static void test1() {
void *data = 0;
my_malloc1(&data, 4); }
static void test11() {
void *data = 0;
my_malloc1(&data, 4);
my_free1(data);
}
static void testUniqueingByallocationSiteInTopLevelFunction() {
void *data = my_malloc2(1, 4);
data = 0;
int x = 5; data = my_malloc2(1, 4);}
static void test3() {
void *data = my_malloc2(1, 4);
free(data);
data = my_malloc2(1, 4);
free(data);
}
int test4() {
int *data = (int*)my_malloc2(1, 4);
my_free1(data);
data = (int *)my_malloc2(1, 4);
my_free1(data);
return *data; }
void test6() {
int *data = (int *)my_malloc2(1, 4);
my_free1((int*)data);
my_free1((int*)data); }
void test5() {
int *data;
my_free1((int*)data);
}
static char *reshape(char *in) {
return 0;
}
void testThatRemoveDeadBindingsRunBeforeEachCall() {
char *v = malloc(12);
v = reshape(v);
v = reshape(v);}
void fooWithEmptyReturn(int x) {
if (x)
return;
x++;
return;
}
int uafAndCallsFooWithEmptyReturn() {
int *x = (int*)malloc(12);
free(x);
fooWithEmptyReturn(12);
return *x; }
char *strndup(const char *str, size_t n) {
if (!str)
return 0;
if (n < 5)
return 0;
size_t length = strlen(str);
if (length < n)
n = length;
char *result = malloc(n + 1);
memcpy(result, str, n);
result[n] = '\0';
return result;
}
void useStrndup(size_t n) {
if (n == 0)
(void)strndup(0, 20); else if (n < 5)
(void)strndup("hi there", n); else
(void)strndup("hi there", n); }