#ifdef USE_BUILTINS
# define BUILTIN(f) __builtin_ ## f
#else
# define BUILTIN(f) f
#endif
#define NULL 0
typedef typeof(sizeof(int)) size_t;
void clang_analyzer_eval(int);
int scanf(const char *restrict format, ...);
void *malloc(size_t);
void free(void *);
#define strlen BUILTIN(strlen)
size_t strlen(const char *s);
void strlen_constant0(void) {
clang_analyzer_eval(strlen("123") == 3); }
void strlen_constant1(void) {
const char *a = "123";
clang_analyzer_eval(strlen(a) == 3); }
void strlen_constant2(char x) {
char a[] = "123";
clang_analyzer_eval(strlen(a) == 3);
a[0] = x;
clang_analyzer_eval(strlen(a) == 3); }
size_t strlen_null(void) {
return strlen(0); }
size_t strlen_fn(void) {
return strlen((char*)&strlen_fn); }
size_t strlen_nonloc(void) {
label:
return strlen((char*)&&label); }
void strlen_subregion(void) {
struct two_strings { char a[2], b[2]; };
extern void use_two_strings(struct two_strings *);
struct two_strings z;
use_two_strings(&z);
size_t a = strlen(z.a);
z.b[0] = 5;
size_t b = strlen(z.a);
if (a == 0)
clang_analyzer_eval(b == 0);
use_two_strings(&z);
size_t c = strlen(z.a);
if (a == 0)
clang_analyzer_eval(c == 0); }
extern void use_string(char *);
void strlen_argument(char *x) {
size_t a = strlen(x);
size_t b = strlen(x);
if (a == 0)
clang_analyzer_eval(b == 0);
use_string(x);
size_t c = strlen(x);
if (a == 0)
clang_analyzer_eval(c == 0); }
extern char global_str[];
void strlen_global(void) {
size_t a = strlen(global_str);
size_t b = strlen(global_str);
if (a == 0) {
clang_analyzer_eval(b == 0); clang_analyzer_eval(strlen(global_str) == 0); }
use_string(0);
size_t c = strlen(global_str);
if (a == 0)
clang_analyzer_eval(c == 0); }
void strlen_indirect(char *x) {
size_t a = strlen(x);
char *p = x;
char **p2 = &p;
size_t b = strlen(x);
if (a == 0)
clang_analyzer_eval(b == 0);
extern void use_string_ptr(char*const*);
use_string_ptr(p2);
size_t c = strlen(x);
if (a == 0)
clang_analyzer_eval(c == 0); }
void strlen_indirect2(char *x) {
size_t a = strlen(x);
char *p = x;
char **p2 = &p;
extern void use_string_ptr2(char**);
use_string_ptr2(p2);
size_t c = strlen(x);
if (a == 0)
clang_analyzer_eval(c == 0); }
void strlen_liveness(const char *x) {
if (strlen(x) < 5)
return;
clang_analyzer_eval(strlen(x) < 5); }
size_t strlenWrapper(const char *str) {
return strlen(str);
}
extern void invalidate(char *s);
void testStrlenCallee(void) {
char str[42];
invalidate(str);
size_t lenBefore = strlenWrapper(str);
invalidate(str);
size_t lenAfter = strlenWrapper(str);
clang_analyzer_eval(lenBefore == lenAfter); }
size_t strnlen(const char *s, size_t maxlen);
void strnlen_constant0(void) {
clang_analyzer_eval(strnlen("123", 10) == 3); }
void strnlen_constant1(void) {
const char *a = "123";
clang_analyzer_eval(strnlen(a, 10) == 3); }
void strnlen_constant2(char x) {
char a[] = "123";
clang_analyzer_eval(strnlen(a, 10) == 3); a[0] = x;
clang_analyzer_eval(strnlen(a, 10) == 3); }
void strnlen_constant4(void) {
clang_analyzer_eval(strnlen("123456", 3) == 3); }
void strnlen_constant5(void) {
const char *a = "123456";
clang_analyzer_eval(strnlen(a, 3) == 3); }
void strnlen_constant6(char x) {
char a[] = "123456";
clang_analyzer_eval(strnlen(a, 3) == 3); a[0] = x;
clang_analyzer_eval(strnlen(a, 3) == 3); }
size_t strnlen_null(void) {
return strnlen(0, 3); }
size_t strnlen_fn(void) {
return strnlen((char*)&strlen_fn, 3); }
size_t strnlen_nonloc(void) {
label:
return strnlen((char*)&&label, 3); }
void strnlen_zero(void) {
clang_analyzer_eval(strnlen("abc", 0) == 0); clang_analyzer_eval(strnlen(NULL, 0) == 0); }
size_t strnlen_compound_literal(void) {
return strnlen((char[]) { 'a', 'b', 0 }, 1);
}
size_t strnlen_unknown_limit(float f) {
return strnlen("abc", (int)f);
}
void strnlen_is_not_strlen(char *x) {
clang_analyzer_eval(strnlen(x, 10) == strlen(x)); }
void strnlen_at_limit(char *x) {
size_t len = strnlen(x, 10);
clang_analyzer_eval(len <= 10); clang_analyzer_eval(len == 10); clang_analyzer_eval(len < 10); }
void strnlen_at_actual(size_t limit) {
size_t len = strnlen("abc", limit);
clang_analyzer_eval(len <= 3); if (limit == 0) {
clang_analyzer_eval(len == 0); } else {
clang_analyzer_eval(len == 3); clang_analyzer_eval(len < 3); }
}
#ifdef VARIANT
#define __strcpy_chk BUILTIN(__strcpy_chk)
char *__strcpy_chk(char *restrict s1, const char *restrict s2, size_t destlen);
#define strcpy(a,b) __strcpy_chk(a,b,(size_t)-1)
#else
#define strcpy BUILTIN(strcpy)
char *strcpy(char *restrict s1, const char *restrict s2);
#endif
void strcpy_null_dst(char *x) {
strcpy(NULL, x); }
void strcpy_null_src(char *x) {
strcpy(x, NULL); }
void strcpy_fn(char *x) {
strcpy(x, (char*)&strcpy_fn); }
void strcpy_fn_const(char *x) {
strcpy(x, (const char*)&strcpy_fn); }
extern int globalInt;
void strcpy_effects(char *x, char *y) {
char a = x[0];
if (globalInt != 42)
return;
clang_analyzer_eval(strcpy(x, y) == x); clang_analyzer_eval(strlen(x) == strlen(y)); clang_analyzer_eval(a == x[0]); clang_analyzer_eval(globalInt == 42); }
#ifndef SUPPRESS_OUT_OF_BOUND
void strcpy_overflow(char *y) {
char x[4];
if (strlen(y) == 4)
strcpy(x, y); }
#endif
void strcpy_no_overflow(char *y) {
char x[4];
if (strlen(y) == 3)
strcpy(x, y); }
void *get_void_ptr(void);
char ***type_punned_ptr;
void strcpy_no_assertion(char c) {
*(unsigned char **)type_punned_ptr = (unsigned char *)(get_void_ptr());
strcpy(**type_punned_ptr, &c); }
char f(char ***c, int *i) {
*(void **)c = i + 1;
return (**c)[0]; }
#ifdef VARIANT
#define __stpcpy_chk BUILTIN(__stpcpy_chk)
char *__stpcpy_chk(char *restrict s1, const char *restrict s2, size_t destlen);
#define stpcpy(a,b) __stpcpy_chk(a,b,(size_t)-1)
#else
#define stpcpy BUILTIN(stpcpy)
char *stpcpy(char *restrict s1, const char *restrict s2);
#endif
void stpcpy_effect(char *x, char *y) {
char a = x[0];
clang_analyzer_eval(stpcpy(x, y) == &x[strlen(y)]); clang_analyzer_eval(strlen(x) == strlen(y)); clang_analyzer_eval(a == x[0]); }
#ifndef SUPPRESS_OUT_OF_BOUND
void stpcpy_overflow(char *y) {
char x[4];
if (strlen(y) == 4)
stpcpy(x, y); }
#endif
void stpcpy_no_overflow(char *y) {
char x[4];
if (strlen(y) == 3)
stpcpy(x, y); }
#ifdef VARIANT
#define __strcat_chk BUILTIN(__strcat_chk)
char *__strcat_chk(char *restrict s1, const char *restrict s2, size_t destlen);
#define strcat(a,b) __strcat_chk(a,b,(size_t)-1)
#else
#define strcat BUILTIN(strcat)
char *strcat(char *restrict s1, const char *restrict s2);
#endif
void strcat_null_dst(char *x) {
strcat(NULL, x); }
void strcat_null_src(char *x) {
strcat(x, NULL); }
void strcat_fn(char *x) {
strcat(x, (char*)&strcat_fn); }
void strcat_effects(char *y) {
char x[8] = "123";
size_t orig_len = strlen(x);
char a = x[0];
if (strlen(y) != 4)
return;
clang_analyzer_eval(strcat(x, y) == x); clang_analyzer_eval((int)strlen(x) == (orig_len + strlen(y))); }
#ifndef SUPPRESS_OUT_OF_BOUND
void strcat_overflow_0(char *y) {
char x[4] = "12";
if (strlen(y) == 4)
strcat(x, y); }
void strcat_overflow_1(char *y) {
char x[4] = "12";
if (strlen(y) == 3)
strcat(x, y); }
void strcat_overflow_2(char *y) {
char x[4] = "12";
if (strlen(y) == 2)
strcat(x, y); }
#endif
void strcat_no_overflow(char *y) {
char x[5] = "12";
if (strlen(y) == 2)
strcat(x, y); }
void strcat_symbolic_dst_length(char *dst) {
strcat(dst, "1234");
clang_analyzer_eval(strlen(dst) >= 4); }
void strcat_symbolic_dst_length_taint(char *dst) {
scanf("%s", dst); strcat(dst, "1234");
clang_analyzer_eval(strlen(dst) >= 4); }
void strcat_unknown_src_length(char *src, int offset) {
char dst[8] = "1234";
strcat(dst, &src[offset]);
clang_analyzer_eval(strlen(dst) >= 4); }
void strcat_too_big(char *dst, char *src) {
if (strlen(dst) != (((size_t)0) - 2))
return;
if (strlen(src) != 2)
return;
strcat(dst, src);
}
#ifdef VARIANT
#define __strncpy_chk BUILTIN(__strncpy_chk)
char *__strncpy_chk(char *restrict s1, const char *restrict s2, size_t n, size_t destlen);
#define strncpy(a,b,n) __strncpy_chk(a,b,n,(size_t)-1)
#else
#define strncpy BUILTIN(strncpy)
char *strncpy(char *restrict s1, const char *restrict s2, size_t n);
#endif
void strncpy_null_dst(char *x) {
strncpy(NULL, x, 5); }
void strncpy_null_src(char *x) {
strncpy(x, NULL, 5); }
void strncpy_fn(char *x) {
strncpy(x, (char*)&strcpy_fn, 5); }
void strncpy_effects(char *x, char *y) {
char a = x[0];
clang_analyzer_eval(strncpy(x, y, 5) == x); clang_analyzer_eval(strlen(x) == strlen(y)); clang_analyzer_eval(a == x[0]); }
#ifndef SUPPRESS_OUT_OF_BOUND
void cstringchecker_bounds_nocrash(void) {
char *p = malloc(2);
strncpy(p, "AAA", sizeof("AAA"));
free(p);
}
void strncpy_overflow(char *y) {
char x[4];
if (strlen(y) == 4)
strncpy(x, y, 5);
#ifndef VARIANT
#endif
}
void strncpy_no_overflow(char *y) {
char x[4];
if (strlen(y) == 3)
strncpy(x, y, 5);
#ifndef VARIANT
#endif
}
void strncpy_no_overflow2(char *y, int n) {
if (n <= 4)
return;
char x[4];
if (strlen(y) == 3)
strncpy(x, y, n);
}
#endif
void strncpy_truncate(char *y) {
char x[4];
if (strlen(y) == 4)
strncpy(x, y, 3); }
void strncpy_no_truncate(char *y) {
char x[4];
if (strlen(y) == 3)
strncpy(x, y, 3); }
void strncpy_exactly_matching_buffer(char *y) {
char x[4];
strncpy(x, y, 4);
clang_analyzer_eval(strlen(x) > 4); }
void strncpy_zero(char *src) {
char dst[] = "123";
strncpy(dst, src, 0); }
void strncpy_empty(void) {
char dst[] = "123";
char src[] = "";
strncpy(dst, src, 4); }
#ifdef VARIANT
#define __strncat_chk BUILTIN(__strncat_chk)
char *__strncat_chk(char *restrict s1, const char *restrict s2, size_t n, size_t destlen);
#define strncat(a,b,c) __strncat_chk(a,b,c, (size_t)-1)
#else
#define strncat BUILTIN(strncat)
char *strncat(char *restrict s1, const char *restrict s2, size_t n);
#endif
void strncat_null_dst(char *x) {
strncat(NULL, x, 4); }
void strncat_null_src(char *x) {
strncat(x, NULL, 4); }
void strncat_fn(char *x) {
strncat(x, (char*)&strncat_fn, 4); }
void strncat_effects(char *y) {
char x[8] = "123";
size_t orig_len = strlen(x);
char a = x[0];
if (strlen(y) != 4)
return;
clang_analyzer_eval(strncat(x, y, strlen(y)) == x); clang_analyzer_eval(strlen(x) == (orig_len + strlen(y))); }
#ifndef SUPPRESS_OUT_OF_BOUND
void strncat_overflow_0(char *y) {
char x[4] = "12";
if (strlen(y) == 4)
strncat(x, y, strlen(y));
}
void strncat_overflow_1(char *y) {
char x[4] = "12";
if (strlen(y) == 3)
strncat(x, y, strlen(y));
}
void strncat_overflow_2(char *y) {
char x[4] = "12";
if (strlen(y) == 2)
strncat(x, y, strlen(y));
}
void strncat_overflow_3(char *y) {
char x[4] = "12";
if (strlen(y) == 4)
strncat(x, y, 2);
}
#endif
void strncat_no_overflow_1(char *y) {
char x[5] = "12";
if (strlen(y) == 2)
strncat(x, y, strlen(y)); }
void strncat_no_overflow_2(char *y) {
char x[4] = "12";
if (strlen(y) == 4)
strncat(x, y, 1); }
void strncat_symbolic_dst_length(char *dst) {
strncat(dst, "1234", 5);
clang_analyzer_eval(strlen(dst) >= 4); }
#ifndef SUPPRESS_OUT_OF_BOUND
void strncat_symbolic_src_length(char *src) {
char dst[8] = "1234";
strncat(dst, src, 3);
clang_analyzer_eval(strlen(dst) >= 4);
char dst2[8] = "1234";
strncat(dst2, src, 4);
}
void strncat_unknown_src_length(char *src, int offset) {
char dst[8] = "1234";
strncat(dst, &src[offset], 3);
clang_analyzer_eval(strlen(dst) >= 4);
char dst2[8] = "1234";
strncat(dst2, &src[offset], 4);
}
#endif
void strncat_symbolic_limit(unsigned limit) {
char dst[6] = "1234";
char src[] = "567";
strncat(dst, src, limit);
clang_analyzer_eval(strlen(dst) >= 4); clang_analyzer_eval(strlen(dst) == 4); }
void strncat_unknown_limit(float limit) {
char dst[6] = "1234";
char src[] = "567";
strncat(dst, src, (size_t)limit);
clang_analyzer_eval(strlen(dst) >= 4); clang_analyzer_eval(strlen(dst) == 4); }
void strncat_too_big(char *dst, char *src) {
if (strlen(dst) != (((size_t)0) - 2))
return;
if (strlen(src) != 2)
return;
strncat(dst, src, 2);
}
void strncat_zero(char *src) {
char dst[] = "123";
strncat(dst, src, 0); }
void strncat_empty(void) {
char dst[8] = "123";
char src[] = "";
strncat(dst, src, 4); }
#define strcmp BUILTIN(strcmp)
int strcmp(const char * s1, const char * s2);
void strcmp_check_modelling(void) {
char *x = "aa";
char *y = "a";
clang_analyzer_eval(strcmp(x, y) > 0); clang_analyzer_eval(strcmp(x, y) <= 0); clang_analyzer_eval(strcmp(x, y) > 1);
clang_analyzer_eval(strcmp(y, x) < 0); clang_analyzer_eval(strcmp(y, x) >= 0); clang_analyzer_eval(strcmp(y, x) < -1); }
void strcmp_constant0(void) {
clang_analyzer_eval(strcmp("123", "123") == 0); }
void strcmp_constant_and_var_0(void) {
char *x = "123";
clang_analyzer_eval(strcmp(x, "123") == 0); }
void strcmp_constant_and_var_1(void) {
char *x = "123";
clang_analyzer_eval(strcmp("123", x) == 0); }
void strcmp_0(void) {
char *x = "123";
char *y = "123";
clang_analyzer_eval(strcmp(x, y) == 0); }
void strcmp_1(void) {
char *x = "234";
char *y = "123";
clang_analyzer_eval(strcmp(x, y) > 0); }
void strcmp_2(void) {
char *x = "123";
char *y = "234";
clang_analyzer_eval(strcmp(x, y) < 0); }
void strcmp_null_0(void) {
char *x = NULL;
char *y = "123";
strcmp(x, y); }
void strcmp_null_1(void) {
char *x = "123";
char *y = NULL;
strcmp(x, y); }
void strcmp_diff_length_0(void) {
char *x = "12345";
char *y = "234";
clang_analyzer_eval(strcmp(x, y) < 0); }
void strcmp_diff_length_1(void) {
char *x = "123";
char *y = "23456";
clang_analyzer_eval(strcmp(x, y) < 0); }
void strcmp_diff_length_2(void) {
char *x = "12345";
char *y = "123";
clang_analyzer_eval(strcmp(x, y) > 0); }
void strcmp_diff_length_3(void) {
char *x = "123";
char *y = "12345";
clang_analyzer_eval(strcmp(x, y) < 0); }
void strcmp_embedded_null (void) {
clang_analyzer_eval(strcmp("\0z", "\0y") == 0); }
void strcmp_unknown_arg (char *unknown) {
clang_analyzer_eval(strcmp(unknown, unknown) == 0); }
union argument {
char *f;
};
void function_pointer_cast_helper(char **a) {
strcmp("Hi", *a); }
void strcmp_union_function_pointer_cast(union argument a) {
void (*fPtr)(union argument *) = (void (*)(union argument *))function_pointer_cast_helper;
fPtr(&a);
}
int strcmp_null_argument(char *a) {
char *b = 0;
return strcmp(a, b); }
#define strncmp BUILTIN(strncmp)
int strncmp(const char *s1, const char *s2, size_t n);
void strncmp_check_modelling(void) {
char *x = "aa";
char *y = "a";
clang_analyzer_eval(strncmp(x, y, 2) > 0); clang_analyzer_eval(strncmp(x, y, 2) <= 0); clang_analyzer_eval(strncmp(x, y, 2) > 1);
clang_analyzer_eval(strncmp(y, x, 2) < 0); clang_analyzer_eval(strncmp(y, x, 2) >= 0); clang_analyzer_eval(strncmp(y, x, 2) < -1); }
void strncmp_constant0(void) {
clang_analyzer_eval(strncmp("123", "123", 3) == 0); }
void strncmp_constant_and_var_0(void) {
char *x = "123";
clang_analyzer_eval(strncmp(x, "123", 3) == 0); }
void strncmp_constant_and_var_1(void) {
char *x = "123";
clang_analyzer_eval(strncmp("123", x, 3) == 0); }
void strncmp_0(void) {
char *x = "123";
char *y = "123";
clang_analyzer_eval(strncmp(x, y, 3) == 0); }
void strncmp_1(void) {
char *x = "234";
char *y = "123";
clang_analyzer_eval(strncmp(x, y, 3) > 0); }
void strncmp_2(void) {
char *x = "123";
char *y = "234";
clang_analyzer_eval(strncmp(x, y, 3) < 0); }
void strncmp_null_0(void) {
char *x = NULL;
char *y = "123";
strncmp(x, y, 3); }
void strncmp_null_1(void) {
char *x = "123";
char *y = NULL;
strncmp(x, y, 3); }
void strncmp_diff_length_0(void) {
char *x = "12345";
char *y = "234";
clang_analyzer_eval(strncmp(x, y, 5) < 0); }
void strncmp_diff_length_1(void) {
char *x = "123";
char *y = "23456";
clang_analyzer_eval(strncmp(x, y, 5) < 0); }
void strncmp_diff_length_2(void) {
char *x = "12345";
char *y = "123";
clang_analyzer_eval(strncmp(x, y, 5) > 0); }
void strncmp_diff_length_3(void) {
char *x = "123";
char *y = "12345";
clang_analyzer_eval(strncmp(x, y, 5) < 0); }
void strncmp_diff_length_4(void) {
char *x = "123";
char *y = "12345";
clang_analyzer_eval(strncmp(x, y, 3) == 0); }
void strncmp_diff_length_5(void) {
char *x = "012";
char *y = "12345";
clang_analyzer_eval(strncmp(x, y, 3) < 0); }
void strncmp_diff_length_6(void) {
char *x = "234";
char *y = "12345";
clang_analyzer_eval(strncmp(x, y, 3) > 0); }
void strncmp_embedded_null (void) {
clang_analyzer_eval(strncmp("ab\0zz", "ab\0yy", 4) == 0); }
int strncmp_null_argument(char *a, size_t n) {
char *b = 0;
return strncmp(a, b, n); }
#define strcasecmp BUILTIN(strcasecmp)
int strcasecmp(const char *s1, const char *s2);
void strcasecmp_check_modelling(void) {
char *x = "aa";
char *y = "a";
clang_analyzer_eval(strcasecmp(x, y) > 0); clang_analyzer_eval(strcasecmp(x, y) <= 0); clang_analyzer_eval(strcasecmp(x, y) > 1);
clang_analyzer_eval(strcasecmp(y, x) < 0); clang_analyzer_eval(strcasecmp(y, x) >= 0); clang_analyzer_eval(strcasecmp(y, x) < -1); }
void strcasecmp_constant0(void) {
clang_analyzer_eval(strcasecmp("abc", "Abc") == 0); }
void strcasecmp_constant_and_var_0(void) {
char *x = "abc";
clang_analyzer_eval(strcasecmp(x, "Abc") == 0); }
void strcasecmp_constant_and_var_1(void) {
char *x = "abc";
clang_analyzer_eval(strcasecmp("Abc", x) == 0); }
void strcasecmp_0(void) {
char *x = "abc";
char *y = "Abc";
clang_analyzer_eval(strcasecmp(x, y) == 0); }
void strcasecmp_1(void) {
char *x = "Bcd";
char *y = "abc";
clang_analyzer_eval(strcasecmp(x, y) > 0); }
void strcasecmp_2(void) {
char *x = "abc";
char *y = "Bcd";
clang_analyzer_eval(strcasecmp(x, y) < 0); }
void strcasecmp_null_0(void) {
char *x = NULL;
char *y = "123";
strcasecmp(x, y); }
void strcasecmp_null_1(void) {
char *x = "123";
char *y = NULL;
strcasecmp(x, y); }
void strcasecmp_diff_length_0(void) {
char *x = "abcde";
char *y = "aBd";
clang_analyzer_eval(strcasecmp(x, y) < 0); }
void strcasecmp_diff_length_1(void) {
char *x = "abc";
char *y = "aBdef";
clang_analyzer_eval(strcasecmp(x, y) < 0); }
void strcasecmp_diff_length_2(void) {
char *x = "aBcDe";
char *y = "abc";
clang_analyzer_eval(strcasecmp(x, y) > 0); }
void strcasecmp_diff_length_3(void) {
char *x = "aBc";
char *y = "abcde";
clang_analyzer_eval(strcasecmp(x, y) < 0); }
void strcasecmp_embedded_null (void) {
clang_analyzer_eval(strcasecmp("ab\0zz", "ab\0yy") == 0); }
int strcasecmp_null_argument(char *a) {
char *b = 0;
return strcasecmp(a, b); }
#define strncasecmp BUILTIN(strncasecmp)
int strncasecmp(const char *s1, const char *s2, size_t n);
void strncasecmp_check_modelling(void) {
char *x = "aa";
char *y = "a";
clang_analyzer_eval(strncasecmp(x, y, 2) > 0); clang_analyzer_eval(strncasecmp(x, y, 2) <= 0); clang_analyzer_eval(strncasecmp(x, y, 2) > 1);
clang_analyzer_eval(strncasecmp(y, x, 2) < 0); clang_analyzer_eval(strncasecmp(y, x, 2) >= 0); clang_analyzer_eval(strncasecmp(y, x, 2) < -1); }
void strncasecmp_constant0(void) {
clang_analyzer_eval(strncasecmp("abc", "Abc", 3) == 0); }
void strncasecmp_constant_and_var_0(void) {
char *x = "abc";
clang_analyzer_eval(strncasecmp(x, "Abc", 3) == 0); }
void strncasecmp_constant_and_var_1(void) {
char *x = "abc";
clang_analyzer_eval(strncasecmp("Abc", x, 3) == 0); }
void strncasecmp_0(void) {
char *x = "abc";
char *y = "Abc";
clang_analyzer_eval(strncasecmp(x, y, 3) == 0); }
void strncasecmp_1(void) {
char *x = "Bcd";
char *y = "abc";
clang_analyzer_eval(strncasecmp(x, y, 3) > 0); }
void strncasecmp_2(void) {
char *x = "abc";
char *y = "Bcd";
clang_analyzer_eval(strncasecmp(x, y, 3) < 0); }
void strncasecmp_null_0(void) {
char *x = NULL;
char *y = "123";
strncasecmp(x, y, 3); }
void strncasecmp_null_1(void) {
char *x = "123";
char *y = NULL;
strncasecmp(x, y, 3); }
void strncasecmp_diff_length_0(void) {
char *x = "abcde";
char *y = "aBd";
clang_analyzer_eval(strncasecmp(x, y, 5) < 0); }
void strncasecmp_diff_length_1(void) {
char *x = "abc";
char *y = "aBdef";
clang_analyzer_eval(strncasecmp(x, y, 5) < 0); }
void strncasecmp_diff_length_2(void) {
char *x = "aBcDe";
char *y = "abc";
clang_analyzer_eval(strncasecmp(x, y, 5) > 0); }
void strncasecmp_diff_length_3(void) {
char *x = "aBc";
char *y = "abcde";
clang_analyzer_eval(strncasecmp(x, y, 5) < 0); }
void strncasecmp_diff_length_4(void) {
char *x = "abcde";
char *y = "aBc";
clang_analyzer_eval(strncasecmp(x, y, 3) == 0); }
void strncasecmp_diff_length_5(void) {
char *x = "abcde";
char *y = "aBd";
clang_analyzer_eval(strncasecmp(x, y, 3) < 0); }
void strncasecmp_diff_length_6(void) {
char *x = "aBDe";
char *y = "abc";
clang_analyzer_eval(strncasecmp(x, y, 3) > 0); }
void strncasecmp_embedded_null (void) {
clang_analyzer_eval(strncasecmp("ab\0zz", "ab\0yy", 4) == 0); }
int strncasecmp_null_argument(char *a, size_t n) {
char *b = 0;
return strncasecmp(a, b, n); }
char *strsep(char **stringp, const char *delim);
void strsep_null_delim(char *s) {
strsep(&s, NULL); }
void strsep_null_search(void) {
strsep(NULL, ""); }
void strsep_return_original_pointer(char *s) {
char *original = s;
char *result = strsep(&s, ""); clang_analyzer_eval(original == result); }
void strsep_null_string(void) {
char *s = NULL;
char *result = strsep(&s, ""); clang_analyzer_eval(result == NULL); }
void strsep_changes_input_pointer(char *s) {
char *original = s;
strsep(&s, ""); clang_analyzer_eval(s == original); clang_analyzer_eval(s == NULL);
if (s == NULL) {
clang_analyzer_eval(s == NULL); }
}
void strsep_changes_input_string(void) {
char str[] = "abc";
clang_analyzer_eval(str[1] == 'b');
char *s = str;
strsep(&s, "b");
clang_analyzer_eval(str[1] == 'b'); }
void *memset(void *dest, int ch, size_t count);
void bzero(void *dst, size_t count);
void explicit_bzero(void *dest, size_t count);
void *malloc(size_t size);
void free(void *);
void memset1_char_array_null(void) {
char str[] = "abcd";
clang_analyzer_eval(strlen(str) == 4); memset(str, '\0', 2);
clang_analyzer_eval(strlen(str) == 0); }
void memset2_char_array_null(void) {
char str[] = "abcd";
clang_analyzer_eval(strlen(str) == 4); memset(str, '\0', strlen(str) + 1);
clang_analyzer_eval(strlen(str) == 0); clang_analyzer_eval(str[2] == 0); }
void memset3_char_malloc_null(void) {
char *str = (char *)malloc(10 * sizeof(char));
memset(str + 1, '\0', 8);
clang_analyzer_eval(str[1] == 0); free(str);
}
void memset4_char_malloc_null(void) {
char *str = (char *)malloc(10 * sizeof(char));
memset(str, '\0', 10);
clang_analyzer_eval(str[1] == 0); clang_analyzer_eval(strlen(str) == 0); free(str);
}
#ifdef SUPPRESS_OUT_OF_BOUND
void memset5_char_malloc_overflow_null(void) {
char *str = (char *)malloc(10 * sizeof(char));
memset(str, '\0', 12);
clang_analyzer_eval(str[1] == 0); free(str);
}
#endif
void memset6_char_array_nonnull(void) {
char str[] = "abcd";
clang_analyzer_eval(strlen(str) == 4); memset(str, '0', 2);
clang_analyzer_eval(str[0] == 'a'); clang_analyzer_eval(strlen(str) == 4); }
#ifdef SUPPRESS_OUT_OF_BOUND
void memset8_char_array_nonnull(void) {
char str[5] = "abcd";
clang_analyzer_eval(strlen(str) == 4); memset(str, '0', 10); clang_analyzer_eval(str[0] != '0'); clang_analyzer_eval(strlen(str) >= 10); clang_analyzer_eval(strlen(str) < 10); }
#endif
struct POD_memset {
int num;
char c;
};
void memset10_struct(void) {
struct POD_memset pod;
char *str = (char *)&pod;
pod.num = 1;
pod.c = 1;
clang_analyzer_eval(pod.num == 0); memset(str, 0, sizeof(struct POD_memset));
clang_analyzer_eval(pod.num == 0); }
#ifdef SUPPRESS_OUT_OF_BOUND
void memset11_struct_field(void) {
struct POD_memset pod;
pod.num = 1;
pod.c = '1';
memset(&pod.num, 0, sizeof(struct POD_memset));
clang_analyzer_eval(pod.num == 0); clang_analyzer_eval(pod.c == '\0'); }
void memset12_struct_field(void) {
struct POD_memset pod;
pod.num = 1;
pod.c = '1';
memset(&pod.c, 0, sizeof(struct POD_memset)); clang_analyzer_eval(pod.num == 0); clang_analyzer_eval(pod.c == 0); }
union U_memset {
int i;
double d;
char c;
};
void memset13_union_field(void) {
union U_memset u;
u.i = 5;
memset(&u.i, '\0', sizeof(union U_memset));
clang_analyzer_eval(u.d == 0); }
#endif
void memset14_region_cast(void) {
char *str = (char *)malloc(10 * sizeof(int));
int *array = (int *)str;
memset(array, 0, 10 * sizeof(int));
clang_analyzer_eval(str[10] == '\0'); clang_analyzer_eval(strlen((char *)array) == 0); clang_analyzer_eval(strlen(str) == 0); free(str);
}
void memset15_region_cast(void) {
char *str = (char *)malloc(10 * sizeof(int));
int *array = (int *)str;
memset(array, 0, 5 * sizeof(int));
clang_analyzer_eval(str[10] == '\0'); clang_analyzer_eval(strlen((char *)array) == 0); clang_analyzer_eval(strlen(str) == 0); free(str);
}
int memset20_scalar(void) {
int *x = malloc(sizeof(int));
*x = 10;
memset(x, 0, sizeof(int));
int num = 1 / *x; free(x);
return num;
}
int memset21_scalar(void) {
int *x = malloc(sizeof(int));
memset(x, 0, 1);
int num = 1 / *x;
free(x);
return num;
}
void memset22_array(void) {
int array[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
clang_analyzer_eval(array[1] == 2); memset(array, 0, sizeof(array));
clang_analyzer_eval(array[1] == 0); }
void memset23_array_pod_object(void) {
struct POD_memset array[10];
array[1].num = 10;
array[1].c = 'c';
clang_analyzer_eval(array[1].num == 10); memset(&array[1], 0, sizeof(struct POD_memset));
clang_analyzer_eval(array[1].num == 0); }
void memset24_array_pod_object(void) {
struct POD_memset array[10];
array[1].num = 10;
array[1].c = 'c';
clang_analyzer_eval(array[1].num == 10); memset(array, 0, sizeof(array));
clang_analyzer_eval(array[1].num == 0); }
void memset25_symbol(char c) {
char array[10] = {1};
if (c != 0)
return;
memset(array, c, 10);
clang_analyzer_eval(strlen(array) == 0); clang_analyzer_eval(array[4] == 0); }
void memset26_upper_UCHAR_MAX(void) {
char array[10] = {1};
memset(array, 1024, 10);
clang_analyzer_eval(strlen(array) == 0); clang_analyzer_eval(array[4] == 0); }
void bzero1_null(void) {
char *a = NULL;
bzero(a, 10); }
void bzero2_char_array_null(void) {
char str[] = "abcd";
clang_analyzer_eval(strlen(str) == 4); bzero(str, 2);
clang_analyzer_eval(strlen(str) == 0); }
void bzero3_char_ptr_null(void) {
char *str = "abcd";
clang_analyzer_eval(strlen(str) == 4); bzero(str + 2, 2);
clang_analyzer_eval(strlen(str) == 0); }
void explicit_bzero1_null(void) {
char *a = NULL;
explicit_bzero(a, 10); }
void explicit_bzero2_clear_mypassword(void) {
char passwd[7] = "passwd";
explicit_bzero(passwd, sizeof(passwd));
clang_analyzer_eval(strlen(passwd) == 0); clang_analyzer_eval(passwd[0] == '\0'); }
void explicit_bzero3_out_ofbound(void) {
char *privkey = (char *)malloc(7);
const char newprivkey[10] = "mysafekey";
strcpy(privkey, "random");
explicit_bzero(privkey, sizeof(newprivkey));
#ifndef SUPPRESS_OUT_OF_BOUND
#endif
clang_analyzer_eval(privkey[0] == '\0');
#ifdef SUPPRESS_OUT_OF_BOUND
#endif
free(privkey);
}
void strcat_symbolic_src_length(char *src) {
char dst[8] = "1234";
strcat(dst, src);
clang_analyzer_eval(strlen(dst) >= 4); }
void strncpy_exactly_matching_buffer2(char *y) {
if (strlen(y) >= 4)
return;
char x[4];
strncpy(x, y, 4);
clang_analyzer_eval(strlen(x) <= 3); }
void memset7_char_array_nonnull(void) {
char str[5] = "abcd";
clang_analyzer_eval(strlen(str) == 4); memset(str, '0', 5);
clang_analyzer_eval(str[0] == '0'); clang_analyzer_eval(strlen(str) >= 5); }
void memset16_region_cast(void) {
char *str = (char *)malloc(10 * sizeof(int));
int *array = (int *)str;
memset(array, '0', 10 * sizeof(int));
clang_analyzer_eval(str[10] == '0'); clang_analyzer_eval(strlen((char *)array) >= 10 * sizeof(int)); clang_analyzer_eval(strlen(str) >= 10 * sizeof(int)); free(str);
}
#ifdef SUPPRESS_OUT_OF_BOUND
void memset17_region_cast(void) {
char *str = (char *)malloc(10 * sizeof(int));
int *array = (int *)str;
memset(array, '0', 12 * sizeof(int));
clang_analyzer_eval(str[10] == '0'); clang_analyzer_eval(strlen((char *)array) >= 12 * sizeof(int)); clang_analyzer_eval(strlen(str) >= 12 * sizeof(int)); free(str);
}
void memset18_memset_multiple_times(void) {
char *str = (char *)malloc(10 * sizeof(char));
clang_analyzer_eval(strlen(str) == 0);
memset(str + 2, '\0', 10 * sizeof(char));
clang_analyzer_eval(strlen(str) == 0); clang_analyzer_eval(str[1] == '\0');
memset(str, '0', 10 * sizeof(char));
clang_analyzer_eval(strlen(str) >= 10); clang_analyzer_eval(str[1] == '0');
free(str);
}
void memset19_memset_multiple_times(void) {
char *str = (char *)malloc(10 * sizeof(char));
clang_analyzer_eval(strlen(str) == 0);
memset(str, '0', 10 * sizeof(char));
clang_analyzer_eval(strlen(str) >= 10); clang_analyzer_eval(str[1] == '0');
memset(str + 2, '\0', 10 * sizeof(char));
clang_analyzer_eval(strlen(str) >= 10); clang_analyzer_eval(str[1] == '0');
free(str);
}
#endif
void memset27_symbol(char c) {
char array[10] = {0};
if (c < 10)
return;
memset(array, c, 10);
clang_analyzer_eval(strlen(array) >= 10); clang_analyzer_eval(array[4] >= 10); }
void memset28(void) {
short x;
memset(&x, 1, sizeof(short));
clang_analyzer_eval(x == 0x101); }
void memset29_plain_int_zero(void) {
short x;
memset(&x, 0, sizeof(short));
clang_analyzer_eval(x == 0); }
void test_memset_chk(void) {
int x;
__builtin___memset_chk(&x, 0, sizeof(x), __builtin_object_size(&x, 0));
clang_analyzer_eval(x == 0); }
#ifndef SUPPRESS_OUT_OF_BOUND
void strcpy_no_overflow_2(char *y) {
char x[3];
strcpy(x, "12\0"); }
#else
void strcpy_no_overflow_2(char *y) {
char x[3];
strcpy(x, "12\0");
}
#endif