#include "Inputs/system-header-simulator.h"
void clang_analyzer_eval(int);
void clang_analyzer_dump(int);
void clang_analyzer_dumpExtent(void *);
#if !defined(_WCHAR_T_DEFINED)
typedef unsigned short wchar_t;
#define _WCHAR_T_DEFINED
#endif
typedef __typeof(sizeof(int)) size_t;
void *malloc(size_t);
void *alloca(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);
char *strdup(const char *s);
wchar_t *wcsdup(const wchar_t *s);
char *strndup(const char *s, size_t n);
int memcmp(const void *s1, const void *s2, size_t n);
char *_strdup(const char *strSource);
wchar_t *_wcsdup(const wchar_t *strSource);
void *_alloca(size_t size);
void myfoo(int *p);
void myfooint(int p);
char *fooRetPtr(void);
void f1(void) {
int *p = malloc(12);
return; }
void f2(void) {
int *p = malloc(12);
free(p);
free(p); }
void f2_realloc_0(void) {
int *p = malloc(12);
realloc(p,0);
realloc(p,0); }
void f2_realloc_1(void) {
int *p = malloc(12);
int *q = realloc(p,0); }
void reallocNotNullPtr(unsigned sizeIn) {
unsigned size = 12;
char *p = (char*)malloc(size);
if (p) {
char *q = (char*)realloc(p, sizeIn);
char x = *q; }
}
void allocaTest(void) {
int *p = alloca(sizeof(int));
}
void winAllocaTest(void) {
int *p = _alloca(sizeof(int));
}
void allocaBuiltinTest(void) {
int *p = __builtin_alloca(sizeof(int));
}
int *realloctest1(void) {
int *q = malloc(12);
q = realloc(q, 20);
return q; }
void reallocFails(void) {
char *p = malloc(12);
char *r = realloc(p, 12+1);
if (!r) {
free(p);
} else {
free(r);
}
}
void reallocSizeZero1(void) {
char *p = malloc(12);
char *r = realloc(p, 0);
if (!r) {
free(p); } else {
free(r);
}
}
void reallocSizeZero2(void) {
char *p = malloc(12);
char *r = realloc(p, 0);
if (!r) {
free(p); } else {
free(r);
}
free(p); }
void reallocSizeZero3(void) {
char *p = malloc(12);
char *r = realloc(p, 0);
free(r);
}
void reallocSizeZero4(void) {
char *r = realloc(0, 0);
free(r);
}
void reallocSizeZero5(void) {
char *r = realloc(0, 0);
}
void reallocPtrZero1(void) {
char *r = realloc(0, 12);
}
void reallocPtrZero2(void) {
char *r = realloc(0, 12);
if (r)
free(r);
}
void reallocPtrZero3(void) {
char *r = realloc(0, 12);
free(r);
}
void reallocRadar6337483_1(void) {
char *buf = malloc(100);
buf = (char*)realloc(buf, 0x1000000);
if (!buf) {
return; }
free(buf);
}
void reallocRadar6337483_2(void) {
char *buf = malloc(100);
char *buf2 = (char*)realloc(buf, 0x1000000);
if (!buf2) {
;
} else {
free(buf2);
}
}
void reallocRadar6337483_3(void) {
char * buf = malloc(100);
char * tmp;
tmp = (char*)realloc(buf, 0x1000000);
if (!tmp) {
free(buf);
return;
}
buf = tmp;
free(buf);
}
void reallocRadar6337483_4(void) {
char *buf = malloc(100);
char *buf2 = (char*)realloc(buf, 0x1000000);
if (!buf2) {
return; } else {
free(buf2);
}
}
int *reallocfTest1(void) {
int *q = malloc(12);
q = reallocf(q, 20);
return q; }
void reallocfRadar6337483_4(void) {
char *buf = malloc(100);
char *buf2 = (char*)reallocf(buf, 0x1000000);
if (!buf2) {
return; } else {
free(buf2);
}
}
void reallocfRadar6337483_3(void) {
char * buf = malloc(100);
char * tmp;
tmp = (char*)reallocf(buf, 0x1000000);
if (!tmp) {
free(buf); return;
}
buf = tmp;
free(buf);
}
void reallocfPtrZero1(void) {
char *r = reallocf(0, 12);
}
void CheckUseZeroAllocatedNoWarn1(void) {
int *p = malloc(0);
free(p); }
void CheckUseZeroAllocatedNoWarn2(void) {
int *p = alloca(0); }
void CheckUseZeroWinAllocatedNoWarn2(void) {
int *p = _alloca(0); }
void CheckUseZeroAllocatedNoWarn3(void) {
int *p = malloc(0);
int *q = realloc(p, 8); free(q);
}
void CheckUseZeroAllocatedNoWarn4(void) {
int *p = realloc(0, 8);
*p = 1; free(p);
}
void CheckUseZeroAllocated1(void) {
int *p = malloc(0);
*p = 1; free(p);
}
char CheckUseZeroAllocated2(void) {
char *p = alloca(0);
return *p; }
char CheckUseZeroWinAllocated2(void) {
char *p = _alloca(0);
return *p; }
void UseZeroAllocated(int *p) {
if (p)
*p = 7; }
void CheckUseZeroAllocated3(void) {
int *p = malloc(0);
UseZeroAllocated(p);
}
void f(char);
void CheckUseZeroAllocated4(void) {
char *p = valloc(0);
f(*p); free(p);
}
void CheckUseZeroAllocated5(void) {
int *p = calloc(0, 2);
*p = 1; free(p);
}
void CheckUseZeroAllocated6(void) {
int *p = calloc(2, 0);
*p = 1; free(p);
}
void CheckUseZeroAllocated7(void) {
int *p = realloc(0, 0);
*p = 1; free(p);
}
void CheckUseZeroAllocated8(void) {
int *p = malloc(8);
int *q = realloc(p, 0);
*q = 1; free(q);
}
void CheckUseZeroAllocated9(void) {
int *p = realloc(0, 0);
int *q = realloc(p, 0);
*q = 1; free(q);
}
void CheckUseZeroAllocatedPathNoWarn(_Bool b) {
int s = 0;
if (b)
s= 10;
char *p = malloc(s);
if (b)
*p = 1;
free(p);
}
void CheckUseZeroAllocatedPathWarn(_Bool b) {
int s = 10;
if (b)
s= 0;
char *p = malloc(s);
if (b)
*p = 1;
free(p);
}
void CheckUseZeroReallocatedPathNoWarn(_Bool b) {
int s = 0;
if (b)
s= 10;
char *p = malloc(8);
char *q = realloc(p, s);
if (b)
*q = 1;
free(q);
}
void CheckUseZeroReallocatedPathWarn(_Bool b) {
int s = 10;
if (b)
s= 0;
char *p = malloc(8);
char *q = realloc(p, s);
if (b)
*q = 1;
free(q);
}
int *f3(void) {
static int *p = 0;
p = malloc(12);
return p; }
static int *p_f4 = 0;
int *f4(void) {
p_f4 = malloc(12);
return p_f4; }
int *f5(void) {
int *q = malloc(12);
q = realloc(q, 20);
return q; }
void f6(void) {
int *p = malloc(12);
if (!p)
return; else
free(p);
}
void f6_realloc(void) {
int *p = malloc(12);
if (!p)
return; else
realloc(p,0);
}
char *doit2(void);
void pr6069(void) {
char *buf = doit2();
free(buf);
}
void pr6293(void) {
free(0);
}
void f7(void) {
char *x = (char*) malloc(4);
free(x);
x[0] = 'a'; }
void f8(void) {
char *x = (char*) malloc(4);
free(x);
char *y = strndup(x, 4); }
void f7_realloc(void) {
char *x = (char*) malloc(4);
realloc(x,0);
x[0] = 'a'; }
void PR6123(void) {
int *x = malloc(11); }
void PR7217(void) {
int *buf = malloc(2); buf[1] = 'c'; }
void cast_emtpy_struct(void) {
struct st {
};
struct st *s = malloc(sizeof(struct st)); free(s);
}
void cast_struct_1(void) {
struct st {
int i[100];
char j[];
};
struct st *s = malloc(sizeof(struct st)); free(s);
}
void cast_struct_2(void) {
struct st {
int i[100];
char j[0];
};
struct st *s = malloc(sizeof(struct st)); free(s);
}
void cast_struct_3(void) {
struct st {
int i[100];
char j[1];
};
struct st *s = malloc(sizeof(struct st)); free(s);
}
void cast_struct_4(void) {
struct st {
int i[100];
char j[2];
};
struct st *s = malloc(sizeof(struct st)); free(s);
}
void cast_struct_5(void) {
struct st {
char i[200];
char j[1];
};
struct st *s = malloc(sizeof(struct st) - sizeof(char)); free(s);
}
void cast_struct_warn_1(void) {
struct st {
int i[100];
char j[2];
};
struct st *s = malloc(sizeof(struct st) + 2); free(s);
}
void cast_struct_warn_2(void) {
struct st {
int i[100];
char j[2];
};
struct st *s = malloc(2); free(s);
}
void cast_struct_flex_array_1(void) {
struct st {
int i[100];
char j[];
};
struct st *s = malloc(sizeof(struct st) + 3); free(s);
}
void cast_struct_flex_array_2(void) {
struct st {
int i[100];
char j[0];
};
struct st *s = malloc(sizeof(struct st) + 3); free(s);
}
void cast_struct_flex_array_3(void) {
struct st {
int i[100];
char j[1];
};
struct st *s = malloc(sizeof(struct st) + 3); free(s);
}
void cast_struct_flex_array_4(void) {
struct foo {
char f[32];
};
struct st {
char i[100];
struct foo data[];
};
struct st *s = malloc(sizeof(struct st) + 3 * sizeof(struct foo)); free(s);
}
void cast_struct_flex_array_5(void) {
struct foo {
char f[32];
};
struct st {
char i[100];
struct foo data[0];
};
struct st *s = malloc(sizeof(struct st) + 3 * sizeof(struct foo)); free(s);
}
void cast_struct_flex_array_6(void) {
struct foo {
char f[32];
};
struct st {
char i[100];
struct foo data[1];
};
struct st *s = malloc(sizeof(struct st) + 3 * sizeof(struct foo)); free(s);
}
void cast_struct_flex_array_warn_1(void) {
struct foo {
char f[32];
};
struct st {
char i[100];
struct foo data[];
};
struct st *s = malloc(3 * sizeof(struct st) + 3 * sizeof(struct foo)); free(s);
}
void cast_struct_flex_array_warn_2(void) {
struct foo {
char f[32];
};
struct st {
char i[100];
struct foo data[0];
};
struct st *s = malloc(3 * sizeof(struct st) + 3 * sizeof(struct foo)); free(s);
}
void cast_struct_flex_array_warn_3(void) {
struct foo {
char f[32];
};
struct st {
char i[100];
struct foo data[1];
};
struct st *s = malloc(3 * sizeof(struct st) + 3 * sizeof(struct foo)); free(s);
}
void cast_struct_flex_array_warn_4(void) {
struct st {
int i[100];
int j[];
};
struct st *s = malloc(sizeof(struct st) + 3); free(s);
}
void cast_struct_flex_array_warn_5(void) {
struct st {
int i[100];
int j[0];
};
struct st *s = malloc(sizeof(struct st) + 3); free(s);
}
void cast_struct_flex_array_warn_6(void) {
struct st {
int i[100];
int j[1];
};
struct st *s = malloc(sizeof(struct st) + 3); free(s);
}
void mallocCastToVoid(void) {
void *p = malloc(2);
const void *cp = p; free(p);
}
void mallocCastToFP(void) {
void *p = malloc(2);
void (*fp)(void) = p; free(p);
}
char mallocGarbage (void) {
char *buf = malloc(2);
char result = buf[1]; free(buf);
return result;
}
void callocNoFree (void) {
char *buf = calloc(2,2);
return; }
char callocZeroesGood (void) {
char *buf = calloc(2,2);
char result = buf[3]; if (buf[1] == 0) {
free(buf);
}
return result; }
char callocZeroesBad (void) {
char *buf = calloc(2,2);
char result = buf[3]; if (buf[1] != 0) {
free(buf); }
return result; }
void nullFree(void) {
int *p = 0;
free(p); }
void paramFree(int *p) {
myfoo(p);
free(p); myfoo(p); }
int* mallocEscapeRet(void) {
int *p = malloc(12);
return p; }
void mallocEscapeFoo(void) {
int *p = malloc(12);
myfoo(p);
return; }
void mallocEscapeFree(void) {
int *p = malloc(12);
myfoo(p);
free(p);
}
void mallocEscapeFreeFree(void) {
int *p = malloc(12);
myfoo(p);
free(p);
free(p); }
void mallocEscapeFreeUse(void) {
int *p = malloc(12);
myfoo(p);
free(p);
myfoo(p); }
int *myalloc(void);
void myalloc2(int **p);
void mallocEscapeFreeCustomAlloc(void) {
int *p = malloc(12);
myfoo(p);
free(p);
p = myalloc();
free(p); }
void mallocEscapeFreeCustomAlloc2(void) {
int *p = malloc(12);
myfoo(p);
free(p);
myalloc2(&p);
free(p); }
void mallocBindFreeUse(void) {
int *x = malloc(12);
int *y = x;
free(y);
myfoo(x); }
void mallocEscapeMalloc(void) {
int *p = malloc(12);
myfoo(p);
p = malloc(12);
}
void mallocMalloc(void) {
int *p = malloc(12);
p = malloc(12);
}
void mallocFreeMalloc(void) {
int *p = malloc(12);
free(p);
p = malloc(12);
free(p);
}
void mallocFreeUse_params(void) {
int *p = malloc(12);
free(p);
myfoo(p); }
void mallocFreeUse_params2(void) {
int *p = malloc(12);
free(p);
myfooint(*p); }
void mallocFailedOrNot(void) {
int *p = malloc(12);
if (!p)
free(p);
else
free(p);
}
struct StructWithInt {
int g;
};
int *mallocReturnFreed(void) {
int *p = malloc(12);
free(p);
return p; }
int useAfterFreeStruct(void) {
struct StructWithInt *px= malloc(sizeof(struct StructWithInt));
px->g = 5;
free(px);
return px->g; }
void nonSymbolAsFirstArg(int *pp, struct StructWithInt *p);
void mallocEscapeFooNonSymbolArg(void) {
struct StructWithInt *p = malloc(sizeof(struct StructWithInt));
nonSymbolAsFirstArg(&p->g, p);
return; }
void mallocFailedOrNotLeak(void) {
int *p = malloc(12);
if (p == 0)
return; else
return; }
void mallocAssignment(void) {
char *p = malloc(12);
p = fooRetPtr();
}
int vallocTest(void) {
char *mem = valloc(12);
return 0; }
void vallocEscapeFreeUse(void) {
int *p = valloc(12);
myfoo(p);
free(p);
myfoo(p); }
int *Gl;
struct GlStTy {
int *x;
};
struct GlStTy GlS = {0};
void GlobalFree(void) {
free(Gl);
}
void GlobalMalloc(void) {
Gl = malloc(12);
}
void GlobalStructMalloc(void) {
int *a = malloc(12);
GlS.x = a;
}
void GlobalStructMallocFree(void) {
int *a = malloc(12);
GlS.x = a;
free(GlS.x);
}
char *ArrayG[12];
void globalArrayTest(void) {
char *p = (char*)malloc(12);
ArrayG[0] = p;
}
typedef struct _StructWithPtr {
int *memP;
} StructWithPtr;
static StructWithPtr arrOfStructs[10];
void testMalloc(void) {
int *x = malloc(12);
StructWithPtr St;
St.memP = x;
arrOfStructs[0] = St; }
StructWithPtr testMalloc2(void) {
int *x = malloc(12);
StructWithPtr St;
St.memP = x;
return St; }
int *testMalloc3(void) {
int *x = malloc(12);
int *y = x;
return y; }
void testStructLeak(void) {
StructWithPtr St;
St.memP = malloc(12);
return; }
void testElemRegion1(void) {
char *x = (void*)malloc(2);
int *ix = (int*)x;
free(&(x[0]));
}
void testElemRegion2(int **pp) {
int *p = malloc(12);
*pp = p;
free(pp[0]);
}
void testElemRegion3(int **pp) {
int *p = malloc(12);
*pp = p;
free(*pp);
}
unsigned takePtrToPtr(int **p);
void PassTheAddrOfAllocatedData(int f) {
int *p = malloc(12);
if (takePtrToPtr(&p))
f++;
free(p); }
struct X {
int *p;
};
unsigned takePtrToStruct(struct X *s);
int ** foo2(int *g, int f) {
int *p = malloc(12);
struct X *px= malloc(sizeof(struct X));
px->p = p;
if (takePtrToStruct(px))
f++;
free(p);
return 0;
}
struct X* RegInvalidationDetect1(struct X *s2) {
struct X *px= malloc(sizeof(struct X));
px->p = 0;
px = s2;
return px; }
struct X* RegInvalidationGiveUp1(void) {
int *p = malloc(12);
struct X *px= malloc(sizeof(struct X));
px->p = p;
return px;
}
int **RegInvalidationDetect2(int **pp) {
int *p = malloc(12);
pp = &p;
pp++;
return 0;}
extern void exit(int) __attribute__ ((__noreturn__));
void mallocExit(int *g) {
struct xx *p = malloc(12);
if (g != 0)
exit(1);
free(p);
return;
}
extern void __assert_fail (__const char *__assertion, __const char *__file,
unsigned int __line, __const char *__function)
__attribute__ ((__noreturn__));
#define assert(expr) \
((expr) ? (void)(0) : __assert_fail (#expr, __FILE__, __LINE__, __func__))
void mallocAssert(int *g) {
struct xx *p = malloc(12);
assert(g != 0);
free(p);
return;
}
void doNotInvalidateWhenPassedToSystemCalls(char *s) {
char *p = malloc(12);
strlen(p);
strcpy(p, s);
strcpy(s, p);
strcpy(p, p);
memcpy(p, s, 1);
memcpy(s, p, 1);
memcpy(p, p, 1);
}
void escapeSourceContents(char *s) {
char *p = malloc(12);
memcpy(s, &p, 12);
void *p1 = malloc(7);
char *a;
memcpy(&a, &p1, sizeof a);
int *ptrs[2];
int *allocated = (int *)malloc(4);
memcpy(&ptrs[0], &allocated, sizeof(int *));
}
void invalidateDestinationContents(void) {
int *null = 0;
int *p = (int *)malloc(4);
memcpy(&p, &null, sizeof(int *));
int *ptrs1[2]; ptrs1[0] = (int *)malloc(4);
memcpy(ptrs1, &null, sizeof(int *));
int *ptrs2[2]; ptrs2[0] = (int *)malloc(4);
memcpy(&ptrs2[1], &null, sizeof(int *));
int *ptrs3[2]; ptrs3[0] = (int *)malloc(4);
memcpy(&ptrs3[0], &null, sizeof(int *));
}
void symbolLostWithStrcpy(char *s) {
char *p = malloc(12);
p = strcpy(p, s);
free(p);
}
static __inline char *
__inline_strcpy_chk (char *restrict __dest, const char *restrict __src)
{
return __builtin___strcpy_chk (__dest, __src, __builtin_object_size (__dest, 2 > 1));
}
void symbolLostWithStrcpy_InlineStrcpyVersion(char *s) {
char *p = malloc(12);
p = ((__builtin_object_size (p, 0) != (size_t) -1) ? __builtin___strcpy_chk (p, s, __builtin_object_size (p, 2 > 1)) : __inline_strcpy_chk (p, s));
free(p);
}
static void *specialMalloc(int n){
int *p;
p = malloc( n+8 );
if( p ){
p[0] = n;
p++;
}
return p;
}
int *specialMallocWithStruct(void) {
struct StructWithInt *px= malloc(sizeof(struct StructWithInt));
return &(px->g);
}
void testStrdup(const char *s, unsigned validIndex) {
char *s2 = strdup(s);
s2[validIndex + 1] = 'b';
}
void testWinStrdup(const char *s, unsigned validIndex) {
char *s2 = _strdup(s);
s2[validIndex + 1] = 'b';
}
void testWcsdup(const wchar_t *s, unsigned validIndex) {
wchar_t *s2 = wcsdup(s);
s2[validIndex + 1] = 'b';
}
void testWinWcsdup(const wchar_t *s, unsigned validIndex) {
wchar_t *s2 = _wcsdup(s);
s2[validIndex + 1] = 'b';
}
int testStrndup(const char *s, unsigned validIndex, unsigned size) {
char *s2 = strndup(s, size);
s2 [validIndex + 1] = 'b';
if (s2[validIndex] != 'a')
return 0;
else
return 1;}
void testStrdupContentIsDefined(const char *s, unsigned validIndex) {
char *s2 = strdup(s);
char result = s2[1]; free(s2);
}
void testWinStrdupContentIsDefined(const char *s, unsigned validIndex) {
char *s2 = _strdup(s);
char result = s2[1]; free(s2);
}
void testWcsdupContentIsDefined(const wchar_t *s, unsigned validIndex) {
wchar_t *s2 = wcsdup(s);
wchar_t result = s2[1]; free(s2);
}
void testWinWcsdupContentIsDefined(const wchar_t *s, unsigned validIndex) {
wchar_t *s2 = _wcsdup(s);
wchar_t result = s2[1]; free(s2);
}
void testPthereadSpecificEscape(pthread_key_t key) {
void *buf = malloc(12);
pthread_setspecific(key, buf); }
static int releasePtr(void *_ctx) {
free(_ctx);
return 0;
}
FILE *useFunOpen(void) {
void *ctx = malloc(sizeof(int));
FILE *f = funopen(ctx, 0, 0, 0, releasePtr); if (f == 0) {
free(ctx);
}
return f;
}
FILE *useFunOpenNoReleaseFunction(void) {
void *ctx = malloc(sizeof(int));
FILE *f = funopen(ctx, 0, 0, 0, 0);
if (f == 0) {
free(ctx);
}
return f; }
static int readNothing(void *_ctx, char *buf, int size) {
return 0;
}
FILE *useFunOpenReadNoRelease(void) {
void *ctx = malloc(sizeof(int));
FILE *f = funopen(ctx, readNothing, 0, 0, 0);
if (f == 0) {
free(ctx);
}
return f; }
int my_main_no_warning(void) {
char *p = malloc(100);
setvbuf(stdout, p, 0, 100);
return 0;
}
int my_main_no_warning2(void) {
char *p = malloc(100);
setbuf(__stdoutp, p);
return 0;
}
int my_main_warn(FILE *f) {
char *p = malloc(100);
setvbuf(f, p, 0, 100);
return 0;}
void radar10978247(int myValueSize) {
char stackBuffer[128];
char *buffer;
if (myValueSize <= sizeof(stackBuffer))
buffer = stackBuffer;
else
buffer = malloc(myValueSize);
if (buffer != stackBuffer)
free(buffer);
}
void radar10978247_positive(int myValueSize) {
char stackBuffer[128];
char *buffer;
if (myValueSize <= sizeof(stackBuffer))
buffer = stackBuffer;
else
buffer = malloc(myValueSize);
if (buffer == stackBuffer)
return;
else
return; }
struct rdar11269741_a_t {
struct rdar11269741_b_t {
int m;
} n;
};
int rdar11269741(struct rdar11269741_b_t o)
{
struct rdar11269741_a_t *p = (struct rdar11269741_a_t *) malloc(sizeof(*p));
p->n = o;
return p->n.m; }
void *radar11329382(unsigned bl) {
void *ptr = malloc (16);
ptr = ptr + (2 - bl);
return ptr; }
void __assert_rtn(const char *, const char *, int, const char *) __attribute__((__noreturn__));
int strcmp(const char *, const char *);
char *a (void);
void radar11270219(void) {
char *x = a(), *y = a();
(__builtin_expect(!(x && y), 0) ? __assert_rtn(__func__, "/Users/zaks/tmp/ex.c", 24, "x && y") : (void)0);
strcmp(x, y); }
void radar_11358224_test_double_assign_ints_positive_2(void)
{
void *ptr = malloc(16);
ptr = ptr;
}
int const_ptr_and_callback(int, const char*, int n, void(*)(void*));
void r11160612_1(void) {
char *x = malloc(12);
const_ptr_and_callback(0, x, 12, free); }
void r11160612_2(void) {
char *x = malloc(12);
const_ptr_and_callback(0, x, 12, 0);
}
void r11160612_4(void) {
char *x = malloc(12);
sqlite3_bind_text_my(0, x, 12, free); }
void r11160612_5(StWithCallback St) {
void *x = malloc(12);
dealocateMemWhenDoneByVal(x, St);
}
void r11160612_6(StWithCallback St) {
void *x = malloc(12);
dealocateMemWhenDoneByRef(&St, x);
}
int mySub(int, int);
int myAdd(int, int);
int fPtr(unsigned cond, int x) {
return (cond ? mySub : myAdd)(x, x);
}
void dependsOnValueOfPtr(int *g, unsigned f) {
int *p;
if (f) {
p = g;
} else {
p = malloc(12);
}
if (p != g)
free(p);
else
return; return;
}
int CMPRegionHeapToStack(void) {
int x = 0;
int *x1 = malloc(8);
int *x2 = &x;
clang_analyzer_eval(x1 == x2); free(x1);
return x;
}
int CMPRegionHeapToHeap2(void) {
int x = 0;
int *x1 = malloc(8);
int *x2 = malloc(8);
int *x4 = x1;
int *x5 = x2;
clang_analyzer_eval(x4 == x5); free(x1);
free(x2);
return x;
}
int CMPRegionHeapToHeap(void) {
int x = 0;
int *x1 = malloc(8);
int *x4 = x1;
if (x1 == x4) {
free(x1);
return 5/x; }
return x;}
int HeapAssignment(void) {
int m = 0;
int *x = malloc(4);
int *y = x;
*x = 5;
clang_analyzer_eval(*x != *y); free(x);
return 0;
}
int *retPtr(void);
int *retPtrMightAlias(int *x);
int cmpHeapAllocationToUnknown(void) {
int zero = 0;
int *yBefore = retPtr();
int *m = malloc(8);
int *yAfter = retPtrMightAlias(m);
clang_analyzer_eval(yBefore == m); clang_analyzer_eval(yAfter == m); free(m);
return 0;
}
void localArrayTest(void) {
char *p = (char*)malloc(12);
char *ArrayL[12];
ArrayL[0] = p;
}
void localStructTest(void) {
StructWithPtr St;
StructWithPtr *pSt = &St;
pSt->memP = malloc(12);
}
#ifdef __INTPTR_TYPE__
typedef __INTPTR_TYPE__ intptr_t;
typedef unsigned __INTPTR_TYPE__ uintptr_t;
static intptr_t glob;
void test_double_assign_ints(void)
{
void *ptr = malloc (16); glob = (intptr_t)(uintptr_t)ptr;
}
void test_double_assign_ints_positive(void)
{
void *ptr = malloc(16);
(void*)(intptr_t)(uintptr_t)ptr; } #endif
void testCGContextNoLeak(void)
{
void *ptr = malloc(16);
CGContextRef context = CGBitmapContextCreate(ptr);
free(CGBitmapContextGetData(context));
}
void testCGContextLeak(void)
{
void *ptr = malloc(16);
CGContextRef context = CGBitmapContextCreate(ptr);
}
static void finalize_connection_context(void *ctx) {
int *context = ctx;
free(context);
}
void foo (xpc_connection_t peer) {
int *ctx = calloc(1, sizeof(int));
xpc_connection_set_context(peer, ctx);
xpc_connection_set_finalizer_f(peer, finalize_connection_context);
xpc_connection_resume(peer);
}
void freeButNoMalloc(int *p, int x){
if (x) {
free(p);
}
free(p); }
struct HasPtr {
char *p;
};
char* reallocButNoMalloc(struct HasPtr *a, int c, int size) {
int *s;
char *b = realloc(a->p, size);
char *m = realloc(a->p, size); return a->p; }
int reallocButNoMallocPR13674(struct HasPtr *a, int c, int size) {
int *s;
char *b = realloc(a->p, size);
if (b == 0)
return -1;
a->p = b;
return 0;
}
void *test(void *ptr) {
void *newPtr = realloc(ptr, 4);
if (newPtr == 0) {
if (ptr)
free(ptr); }
return newPtr;
}
char *testLeakWithinReturn(char *str) {
return strdup(strdup(str)); }
char *testWinLeakWithinReturn(char *str) {
return _strdup(_strdup(str)); }
wchar_t *testWinWideLeakWithinReturn(wchar_t *str) {
return _wcsdup(_wcsdup(str)); }
void passConstPtr(const char * ptr);
void testPassConstPointer(void) {
char * string = malloc(sizeof(char)*10);
passConstPtr(string);
return; }
void testPassConstPointerIndirectly(void) {
char *p = malloc(1);
p++;
memcmp(p, p, sizeof(&p));
return; }
void testPassConstPointerIndirectlyStruct(void) {
struct HasPtr hp;
hp.p = malloc(10);
memcmp(&hp, &hp, sizeof(hp));
return; }
void testPassToSystemHeaderFunctionIndirectlyStruct(void) {
SomeStruct ss;
ss.p = malloc(1);
fakeSystemHeaderCall(&ss); }
void testPassToSystemHeaderFunctionIndirectlyStructFree(void) {
SomeStruct ss;
ss.p = malloc(1);
fakeSystemHeaderCall(&ss); free(ss.p);
}
void testPassToSystemHeaderFunctionIndirectlyArray(void) {
int *p[1];
p[0] = malloc(sizeof(int));
fakeSystemHeaderCallIntPtr(p); }
void testPassToSystemHeaderFunctionIndirectlyArrayFree(void) {
int *p[1];
p[0] = malloc(sizeof(int));
fakeSystemHeaderCallIntPtr(p); free(p[0]);
}
int *testOffsetAllocate(size_t size) {
int *memoryBlock = (int *)malloc(size + sizeof(int));
return &memoryBlock[1]; }
void testOffsetDeallocate(int *memoryBlock) {
free(&memoryBlock[-1]); }
void testOffsetOfRegionFreed(void) {
__int64_t * array = malloc(sizeof(__int64_t)*2);
array += 1;
free(&array[0]); }
void testOffsetOfRegionFreed2(void) {
__int64_t *p = malloc(sizeof(__int64_t)*2);
p += 1;
free(p); }
void testOffsetOfRegionFreed3(void) {
char *r = malloc(sizeof(char));
r = r - 10;
free(r); }
void testOffsetOfRegionFreedAfterFunctionCall(void) {
int *p = malloc(sizeof(int)*2);
p += 1;
myfoo(p);
free(p); }
void testFixManipulatedPointerBeforeFree(void) {
int * array = malloc(sizeof(int)*2);
array += 1;
free(&array[-1]); }
void testFixManipulatedPointerBeforeFree2(void) {
char *r = malloc(sizeof(char));
r = r + 10;
free(r-10); }
void freeOffsetPointerPassedToFunction(void) {
__int64_t *p = malloc(sizeof(__int64_t)*2);
p[1] = 0;
p += 1;
myfooint(*p); free(p); }
int arbitraryInt(void);
void freeUnknownOffsetPointer(void) {
char *r = malloc(sizeof(char));
r = r + arbitraryInt(); free(r); }
void testFreeNonMallocPointerWithNoOffset(void) {
char c;
char *r = &c;
r = r + 10;
free(r-10); }
void testFreeNonMallocPointerWithOffset(void) {
char c;
char *r = &c;
free(r+1); }
void testOffsetZeroDoubleFree(void) {
int *array = malloc(sizeof(int)*2);
int *p = &array[0];
free(p);
free(&array[0]); }
void testOffsetPassedToStrlen(void) {
char * string = malloc(sizeof(char)*10);
string += 1;
int length = strlen(string); }
void testOffsetPassedToStrlenThenFree(void) {
char * string = malloc(sizeof(char)*10);
string += 1;
int length = strlen(string);
free(string); }
void testOffsetPassedAsConst(void) {
char * string = malloc(sizeof(char)*10);
string += 1;
passConstPtr(string);
free(string); }
char **_vectorSegments;
int _nVectorSegments;
void poolFreeC(void* s) {
free(s); }
void freeMemory(void) {
while (_nVectorSegments) {
poolFreeC(_vectorSegments[_nVectorSegments++]);
}
}
void testReallocEscaped(void **memory) {
*memory = malloc(47);
char *new_memory = realloc(*memory, 47);
if (new_memory != 0) {
*memory = new_memory;
}
}
void *smallocNoWarn(size_t size) {
if (size == 0) {
return malloc(1); }
else {
return malloc(size);
}
}
char *dupstrNoWarn(const char *s) {
const int len = strlen(s);
char *p = (char*) smallocNoWarn(len + 1);
strcpy(p, s); return p;
}
void *smallocWarn(size_t size) {
if (size == 2) {
return malloc(1);
}
else {
return malloc(size);
}
}
int *radar15580979(void) {
int *data = (int *)malloc(32);
int *p = data ?: (int*)malloc(32); return p;
}
void testEscapeThroughSystemCallTakingVoidPointer1(void *queue) {
int *data = (int *)malloc(32);
fake_insque(queue, data); }
void testEscapeThroughSystemCallTakingVoidPointer2(fake_rb_tree_t *rbt) {
int *data = (int *)malloc(32);
fake_rb_tree_init(rbt, data);
}
void testEscapeThroughSystemCallTakingVoidPointer3(fake_rb_tree_t *rbt) {
int *data = (int *)malloc(32);
fake_rb_tree_init(rbt, data);
fake_rb_tree_insert_node(rbt, data); }
struct IntAndPtr {
int x;
int *p;
};
void constEscape(const void *ptr);
void testConstEscapeThroughAnotherField(void) {
struct IntAndPtr s;
s.p = malloc(sizeof(int));
constEscape(&(s.x)); }
int testNoCheckerDataPropogationFromLogicalOpOperandToOpResult(void) {
char *param = malloc(10);
char *value = malloc(10);
int ok = (param && value);
free(param);
free(value);
return ok; }
void (*fnptr)(int);
void freeIndirectFunctionPtr(void) {
void *p = (void *)fnptr;
free(p); }
void freeFunctionPtr(void) {
free((void *)fnptr);
}
void allocateSomeMemory(void *offendingParameter, void **ptr) {
*ptr = malloc(1);
}
void testNoCrashOnOffendingParameter(void) {
extern void *offendingParameter;
void* ptr;
allocateSomeMemory(offendingParameter, &ptr);
}
struct A {
int *buf;
};
struct B {
struct A *a;
};
void livenessBugRealloc(struct A *a) {
a->buf = realloc(a->buf, sizeof(int)); }
void testLivenessBug(struct B *in_b) {
struct B *b = in_b;
livenessBugRealloc(b->a);
((void) 0); livenessBugRealloc(b->a);
}
struct ListInfo {
struct ListInfo *next;
};
struct ConcreteListItem {
struct ListInfo li;
int i;
};
void list_add(struct ListInfo *list, struct ListInfo *item);
void testCStyleListItems(struct ListInfo *list) {
struct ConcreteListItem *x = malloc(sizeof(struct ConcreteListItem));
list_add(list, &x->li); }
enum { BUFSIZE = 256 };
void MEM34_C(void) {
char buf[BUFSIZE];
char *p = (char *)realloc(buf, 2 * BUFSIZE);
if (p == NULL) {
}
}
(*crash_a)(); crash_b() { crash_a(); }
long *global_a;
void realloc_crash(void) {
long *c = global_a;
c--;
realloc(c, 8); }
void testMallocWithParam(int **p) {
*p = (int*) malloc(sizeof(int));
*p = 0; }
void testMallocWithParam_2(int **p) {
*p = (int*) malloc(sizeof(int)); }
void testPassToSystemHeaderFunctionIndirectly(void) {
int *p = malloc(4);
p++;
fakeSystemHeaderCallInt(p);
}
void testMallocIntoMalloc(void) {
StructWithPtr *s = malloc(sizeof(StructWithPtr));
s->memP = malloc(sizeof(int));
free(s);
}
int conjure(void);
void testExtent(void) {
int x = conjure();
clang_analyzer_dump(x);
int *p = (int *)malloc(x);
clang_analyzer_dumpExtent(p);
free(p);
}