1// Test strict_string_checks option in strchr function
2// RUN: %clang_asan %s -o %t && %run %t 2>&1
3// RUN: %env_asan_opts=strict_string_checks=false %run %t 2>&1
4// RUN: %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s
5
6#include <assert.h>
7#include <stdlib.h>
8#include <string.h>
9
10int main(int argc, char **argv) {
11 size_t size = 100;
12 char fill = 'o';
13 char *s = (char*)malloc(size: size);
14 memset(s: s, c: fill, n: size);
15 char c = 'o';
16 char* r = strchr(s: s, c: c);
17 // CHECK: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
18 // CHECK: READ of size 101
19 assert(r == s);
20 free(ptr: s);
21 return 0;
22}
23

source code of compiler-rt/test/asan/TestCases/strchr_strict.c