blob: 7198f9a08723a4287426cdd69c53897f663a97fc [file] [log] [blame]
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -07001// Test strict_string_checks option in strcspn function
2// RUN: %clang_asan %s -o %t && %run %t 2>&1
3// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:strict_string_checks=false %run %t 2>&1
4// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS: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 *s1 = (char*)malloc(size);
14 char *s2 = (char*)malloc(size);
15 memset(s1, fill, size);
16 s1[0] = 'z';
17 memset(s2, fill, size);
18 s2[size-1] = '\0';
19 size_t r = strcspn(s1, s2);
20 // CHECK: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
21 // CHECK: READ of size 101
22 assert(r == 1);
23 free(s1);
24 free(s2);
25 return 0;
26}