1 // Check that we fill malloc-ed memory correctly.
2 // RUN: %clangxx_hwasan %s -o %t
3 // RUN: %run %t | FileCheck %s --check-prefix=CHECK-0
4 // RUN: %env_hwasan_opts=max_malloc_fill_size=20 %run %t | FileCheck %s --check-prefix=CHECK-20-be
5 // RUN: %env_hwasan_opts=max_malloc_fill_size=0:malloc_fill_byte=8 %run %t | FileCheck %s --check-prefix=CHECK-0
6 // RUN: %env_hwasan_opts=max_malloc_fill_size=10:malloc_fill_byte=8 %run %t | FileCheck %s --check-prefix=CHECK-10-8
7 // RUN: %env_hwasan_opts=max_malloc_fill_size=20:malloc_fill_byte=171 %run %t | FileCheck %s --check-prefix=CHECK-20-ab
8
9 #include <stdio.h>
10
11 #include "utils.h"
12
main(int argc,char ** argv)13 int main(int argc, char **argv) {
14 // With asan allocator this makes sure we get memory from mmap.
15 static const int kSize = 1 << 25;
16 unsigned char *x = new unsigned char[kSize];
17 untag_printf("-");
18 for (int i = 0; i <= 32; i++) {
19 untag_printf("%02x", x[i]);
20 }
21 untag_printf("-\n");
22 delete [] x;
23 }
24
25 // CHECK-0: -000000000000000000000000000000000000000000000000000000000000000000-
26 // CHECK-20-be: -bebebebebebebebebebebebebebebebebebebebe00000000000000000000000000-
27 // CHECK-10-8: -080808080808080808080000000000000000000000000000000000000000000000-
28 // CHECK-20-ab: -abababababababababababababababababababab00000000000000000000000000-
29