diff options
author | Reid Kleckner <rnk@google.com> | 2016-11-14 17:51:11 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2016-11-14 17:51:11 +0000 |
commit | 127c0e7adbee921a565916f37bc89f5695787131 (patch) | |
tree | 0063860097255bdf26170948ea81be97fccf5353 | |
parent | 1e54762246e3d1f634e2844fe914710322775fef (diff) |
Split strncmp and strncasecmp test and XFAIL one for Windows
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@286850 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | test/asan/TestCases/strncasecmp_strict.c | 67 | ||||
-rw-r--r-- | test/asan/TestCases/strncmp_strict.c | 38 |
2 files changed, 78 insertions, 27 deletions
diff --git a/test/asan/TestCases/strncasecmp_strict.c b/test/asan/TestCases/strncasecmp_strict.c new file mode 100644 index 000000000..aa658402b --- /dev/null +++ b/test/asan/TestCases/strncasecmp_strict.c @@ -0,0 +1,67 @@ +// Test strict_string_checks option in strncmp function +// RUN: %clang_asan %s -o %t + +// RUN: %env_asan_opts=strict_string_checks=false %run %t a 2>&1 +// RUN: %env_asan_opts=strict_string_checks=true %run %t a 2>&1 +// RUN: not %run %t b 2>&1 | FileCheck %s +// RUN: not %run %t c 2>&1 | FileCheck %s +// RUN: not %run %t d 2>&1 | FileCheck %s +// RUN: not %run %t e 2>&1 | FileCheck %s +// RUN: not %run %t f 2>&1 | FileCheck %s +// RUN: not %run %t g 2>&1 | FileCheck %s +// RUN: %env_asan_opts=strict_string_checks=false %run %t h 2>&1 +// RUN: %env_asan_opts=strict_string_checks=true not %run %t h 2>&1 | FileCheck %s +// RUN: %env_asan_opts=strict_string_checks=false %run %t i 2>&1 +// RUN: %env_asan_opts=strict_string_checks=true not %run %t i 2>&1 | FileCheck %s + +// XFAIL: win32 + +#include <assert.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <ctype.h> + +int main(int argc, char **argv) { + assert(argc >= 2); + const size_t size = 100; + char fill = 'o'; + char s1[size]; + char s2[size]; + memset(s1, fill, size); + memset(s2, fill, size); + + switch (argv[1][0]) { + case 'a': + s1[size - 1] = 'z'; + s2[size - 1] = 'x'; + for (int i = 0; i <= size; ++i) + assert((strncasecmp(s1, s2, i) == 0) == (i < size)); + s1[size - 1] = '\0'; + s2[size - 1] = '\0'; + assert(strncasecmp(s1, s2, 2*size) == 0); + break; + case 'b': + return strncasecmp(s1-1, s2, 1); + case 'c': + return strncasecmp(s1, s2-1, 1); + case 'd': + return strncasecmp(s1+size, s2, 1); + case 'e': + return strncasecmp(s1, s2+size, 1); + case 'f': + return strncasecmp(s1+1, s2, size); + case 'g': + return strncasecmp(s1, s2+1, size); + case 'h': + s1[size - 1] = '\0'; + assert(strncasecmp(s1, s2, 2*size) != 0); + break; + case 'i': + s2[size - 1] = '\0'; + assert(strncasecmp(s1, s2, 2*size) != 0); + break; + // CHECK: {{.*}}ERROR: AddressSanitizer: stack-buffer-{{ov|und}}erflow on address + } + return 0; +} diff --git a/test/asan/TestCases/strncmp_strict.c b/test/asan/TestCases/strncmp_strict.c index 5eb3069c0..5b5429064 100644 --- a/test/asan/TestCases/strncmp_strict.c +++ b/test/asan/TestCases/strncmp_strict.c @@ -14,19 +14,6 @@ // RUN: %env_asan_opts=strict_string_checks=false %run %t i 2>&1 // RUN: %env_asan_opts=strict_string_checks=true not %run %t i 2>&1 | FileCheck %s -// RUN: %env_asan_opts=strict_string_checks=false %run %t A 2>&1 -// RUN: %env_asan_opts=strict_string_checks=true %run %t A 2>&1 -// RUN: not %run %t B 2>&1 | FileCheck %s -// RUN: not %run %t C 2>&1 | FileCheck %s -// RUN: not %run %t D 2>&1 | FileCheck %s -// RUN: not %run %t E 2>&1 | FileCheck %s -// RUN: not %run %t F 2>&1 | FileCheck %s -// RUN: not %run %t G 2>&1 | FileCheck %s -// RUN: %env_asan_opts=strict_string_checks=false %run %t H 2>&1 -// RUN: %env_asan_opts=strict_string_checks=true not %run %t H 2>&1 | FileCheck %s -// RUN: %env_asan_opts=strict_string_checks=false %run %t I 2>&1 -// RUN: %env_asan_opts=strict_string_checks=true not %run %t I 2>&1 | FileCheck %s - #include <assert.h> #include <stdlib.h> #include <stdio.h> @@ -42,38 +29,35 @@ int main(int argc, char **argv) { memset(s1, fill, size); memset(s2, fill, size); - int (*cmp_fn)(const char *, const char *, size_t); - cmp_fn = islower(argv[1][0]) ? &strncmp : &strncasecmp; - - switch(tolower(argv[1][0])) { + switch (argv[1][0]) { case 'a': s1[size - 1] = 'z'; s2[size - 1] = 'x'; for (int i = 0; i <= size; ++i) - assert((cmp_fn(s1, s2, i) == 0) == (i < size)); + assert((strncmp(s1, s2, i) == 0) == (i < size)); s1[size - 1] = '\0'; s2[size - 1] = '\0'; - assert(cmp_fn(s1, s2, 2*size) == 0); + assert(strncmp(s1, s2, 2*size) == 0); break; case 'b': - return cmp_fn(s1-1, s2, 1); + return strncmp(s1-1, s2, 1); case 'c': - return cmp_fn(s1, s2-1, 1); + return strncmp(s1, s2-1, 1); case 'd': - return cmp_fn(s1+size, s2, 1); + return strncmp(s1+size, s2, 1); case 'e': - return cmp_fn(s1, s2+size, 1); + return strncmp(s1, s2+size, 1); case 'f': - return cmp_fn(s1+1, s2, size); + return strncmp(s1+1, s2, size); case 'g': - return cmp_fn(s1, s2+1, size); + return strncmp(s1, s2+1, size); case 'h': s1[size - 1] = '\0'; - assert(cmp_fn(s1, s2, 2*size) != 0); + assert(strncmp(s1, s2, 2*size) != 0); break; case 'i': s2[size - 1] = '\0'; - assert(cmp_fn(s1, s2, 2*size) != 0); + assert(strncmp(s1, s2, 2*size) != 0); break; // CHECK: {{.*}}ERROR: AddressSanitizer: stack-buffer-{{ov|und}}erflow on address } |