xref: /aosp_15_r20/external/compiler-rt/test/asan/TestCases/malloc_fill.cc (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // Check that we fill malloc-ed memory correctly.
2*7c3d14c8STreehugger Robot // RUN: %clangxx_asan %s -o %t
3*7c3d14c8STreehugger Robot // RUN: %run %t | FileCheck %s
4*7c3d14c8STreehugger Robot // RUN: %env_asan_opts=max_malloc_fill_size=10:malloc_fill_byte=8 %run %t | FileCheck %s --check-prefix=CHECK-10-8
5*7c3d14c8STreehugger Robot // RUN: %env_asan_opts=max_malloc_fill_size=20:malloc_fill_byte=171 %run %t | FileCheck %s --check-prefix=CHECK-20-ab
6*7c3d14c8STreehugger Robot 
7*7c3d14c8STreehugger Robot #include <stdio.h>
main(int argc,char ** argv)8*7c3d14c8STreehugger Robot int main(int argc, char **argv) {
9*7c3d14c8STreehugger Robot   // With asan allocator this makes sure we get memory from mmap.
10*7c3d14c8STreehugger Robot   static const int kSize = 1 << 25;
11*7c3d14c8STreehugger Robot   unsigned char *x = new unsigned char[kSize];
12*7c3d14c8STreehugger Robot   printf("-");
13*7c3d14c8STreehugger Robot   for (int i = 0; i <= 32; i++) {
14*7c3d14c8STreehugger Robot     printf("%02x", x[i]);
15*7c3d14c8STreehugger Robot   }
16*7c3d14c8STreehugger Robot   printf("-\n");
17*7c3d14c8STreehugger Robot   delete [] x;
18*7c3d14c8STreehugger Robot }
19*7c3d14c8STreehugger Robot 
20*7c3d14c8STreehugger Robot // CHECK: -bebebebebebebebebebebebebebebebebebebebebebebebebebebebebebebebebe-
21*7c3d14c8STreehugger Robot // CHECK-10-8: -080808080808080808080000000000000000000000000000000000000000000000-
22*7c3d14c8STreehugger Robot // CHECK-20-ab: -abababababababababababababababababababab00000000000000000000000000-
23