Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / asan / TestCases / strstr_strict.c
blob8b7153ffc40920e4231f037da58a4a124e9c8169
1 // Test strict_string_checks option in strstr function
2 // RUN: %clang_asan %s -o %t && %run %t 2>&1
4 // Newer versions of Android's strstr() uses memchr() internally, which actually
5 // does trigger a heap-buffer-overflow (as it tries to find the
6 // null-terminator). The same applies to FreeBSD.
7 // UNSUPPORTED: android, target={{.*freebsd.*}}
8 // RUN: %env_asan_opts=strict_string_checks=false %run %t 2>&1
10 // RUN: %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s
12 #include <assert.h>
13 #include <stdlib.h>
14 #include <string.h>
16 int main(int argc, char **argv) {
17 size_t size = 100;
18 char fill = 'o';
19 char *s1 = (char*)malloc(size);
20 char *s2 = (char*)malloc(size);
21 memset(s1, fill, size);
22 memset(s2, fill, size);
23 s2[size - 1]='\0';
24 char* r = strstr(s1, s2);
25 // CHECK: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
26 // CHECK: READ of size {{101|100}}
27 assert(r == s1);
28 free(s1);
29 free(s2);
30 return 0;