blob: 371053480d2cfe58b5133f757ef7226f377ba057 [file] [log] [blame]
Stephen Hines6a211c52014-07-21 00:49:56 -07001// RUN: %clang_cl_asan -O0 %s -Fe%t
Stephen Hines2d1fdb22014-05-28 23:58:16 -07002// RUN: not %run %t 2>&1 | FileCheck %s
3
4#include <stdio.h>
5#include <string.h>
6#include <malloc.h>
7
8int main() {
9 char *ptr = _strdup("Hello");
10 int subscript = 1;
11 ptr[subscript] = '3';
12 printf("%s\n", ptr);
13 fflush(0);
14// CHECK: H3llo
15
16 subscript = -1;
17 ptr[subscript] = 42;
18// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
19// CHECK: WRITE of size 1 at [[ADDR]] thread T0
20// CHECK: {{#0 .* main .*}}intercept_strdup.cc:[[@LINE-3]]
21// CHECK: [[ADDR]] is located 1 bytes to the left of 6-byte region
22// CHECK: allocated by thread T0 here:
23// CHECK: {{#0 .* malloc }}
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080024// FIXME: llvm-symbolizer can't find strdup in the CRT.
25// CHECKX: {{#1 .*strdup}}
26// CHECK: {{#2 .* main .*}}intercept_strdup.cc:[[@LINE-17]]
Stephen Hines2d1fdb22014-05-28 23:58:16 -070027 free(ptr);
28}