diff options
Diffstat (limited to 'test/Analysis/string.c')
-rw-r--r-- | test/Analysis/string.c | 174 |
1 files changed, 106 insertions, 68 deletions
diff --git a/test/Analysis/string.c b/test/Analysis/string.c index 19c838c..e6baf51 100644 --- a/test/Analysis/string.c +++ b/test/Analysis/string.c @@ -328,74 +328,6 @@ void strcpy_no_overflow(char *y) { } //===----------------------------------------------------------------------=== -// strncpy() -//===----------------------------------------------------------------------=== - -#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,c) __strncpy_chk(a,b,c, (size_t)-1) - -#else /* VARIANT */ - -#define strncpy BUILTIN(strncpy) -char *strncpy(char *restrict s1, const char *restrict s2, size_t n); - -#endif /* VARIANT */ - - -void strncpy_null_dst(char *x) { - strncpy(NULL, x, 1); // expected-warning{{Null pointer argument in call to byte string function}} -} - -void strncpy_null_src(char *x) { - strncpy(x, NULL, 1); // expected-warning{{Null pointer argument in call to byte string function}} -} - -void strncpy_fn(char *x) { - strncpy(x, (char*)&strncpy_fn, 1); // expected-warning{{Argument to byte string function is the address of the function 'strncpy_fn', which is not a null-terminated string}} -} - -void strncpy_effects(char *x, char *y) { - char a = x[0]; - - if (strncpy(x, y, strlen(y)) != x) - (void)*(char*)0; // no-warning - - if (strlen(x) != strlen(y)) - (void)*(char*)0; // no-warning - - if (a != x[0]) - (void)*(char*)0; // expected-warning{{null}} -} - -void strncpy_overflow(char *y) { - char x[4]; - if (strlen(y) == 4) - strncpy(x, y, strlen(y)); // expected-warning{{Byte string function overflows destination buffer}} -} - -void strncpy_len_overflow(char *y) { - char x[4]; - if (strlen(y) == 3) - strncpy(x, y, sizeof(x)); // no-warning -} - -void strncpy_no_overflow(char *y) { - char x[4]; - if (strlen(y) == 3) - strncpy(x, y, strlen(y)); // no-warning -} - -void strncpy_no_len_overflow(char *y) { - char x[4]; - if (strlen(y) == 4) - strncpy(x, y, sizeof(x)-1); // no-warning -} - -//===----------------------------------------------------------------------=== // stpcpy() //===----------------------------------------------------------------------=== @@ -872,3 +804,109 @@ void strcasecmp_diff_length_3() { if (strcasecmp(x, y) != -1) (void)*(char*)0; // no-warning } + +//===----------------------------------------------------------------------=== +// strncasecmp() +//===----------------------------------------------------------------------=== + +#define strncasecmp BUILTIN(strncasecmp) +int strncasecmp(const char *restrict s1, const char *restrict s2, size_t n); + +void strncasecmp_constant0() { + if (strncasecmp("abc", "Abc", 3) != 0) + (void)*(char*)0; // no-warning +} + +void strncasecmp_constant_and_var_0() { + char *x = "abc"; + if (strncasecmp(x, "Abc", 3) != 0) + (void)*(char*)0; // no-warning +} + +void strncasecmp_constant_and_var_1() { + char *x = "abc"; + if (strncasecmp("Abc", x, 3) != 0) + (void)*(char*)0; // no-warning +} + +void strncasecmp_0() { + char *x = "abc"; + char *y = "Abc"; + if (strncasecmp(x, y, 3) != 0) + (void)*(char*)0; // no-warning +} + +void strncasecmp_1() { + char *x = "Bcd"; + char *y = "abc"; + if (strncasecmp(x, y, 3) != 1) + (void)*(char*)0; // no-warning +} + +void strncasecmp_2() { + char *x = "abc"; + char *y = "Bcd"; + if (strncasecmp(x, y, 3) != -1) + (void)*(char*)0; // no-warning +} + +void strncasecmp_null_0() { + char *x = NULL; + char *y = "123"; + strncasecmp(x, y, 3); // expected-warning{{Null pointer argument in call to byte string function}} +} + +void strncasecmp_null_1() { + char *x = "123"; + char *y = NULL; + strncasecmp(x, y, 3); // expected-warning{{Null pointer argument in call to byte string function}} +} + +void strncasecmp_diff_length_0() { + char *x = "abcde"; + char *y = "aBd"; + if (strncasecmp(x, y, 5) != -1) + (void)*(char*)0; // no-warning +} + +void strncasecmp_diff_length_1() { + char *x = "abc"; + char *y = "aBdef"; + if (strncasecmp(x, y, 5) != -1) + (void)*(char*)0; // no-warning +} + +void strncasecmp_diff_length_2() { + char *x = "aBcDe"; + char *y = "abc"; + if (strncasecmp(x, y, 5) != 1) + (void)*(char*)0; // no-warning +} + +void strncasecmp_diff_length_3() { + char *x = "aBc"; + char *y = "abcde"; + if (strncasecmp(x, y, 5) != -1) + (void)*(char*)0; // no-warning +} + +void strncasecmp_diff_length_4() { + char *x = "abcde"; + char *y = "aBc"; + if (strncasecmp(x, y, 3) != 0) + (void)*(char*)0; // no-warning +} + +void strncasecmp_diff_length_5() { + char *x = "abcde"; + char *y = "aBd"; + if (strncasecmp(x, y, 3) != -1) + (void)*(char*)0; // no-warning +} + +void strncasecmp_diff_length_6() { + char *x = "aBDe"; + char *y = "abc"; + if (strncasecmp(x, y, 3) != 1) + (void)*(char*)0; // no-warning +} |