• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_scudo -fsized-deallocation %s -o %t
2 // RUN: SCUDO_OPTIONS=DeleteSizeMismatch=1     %run %t gooddel    2>&1
3 // RUN: SCUDO_OPTIONS=DeleteSizeMismatch=1 not %run %t baddel     2>&1 | FileCheck %s
4 // RUN: SCUDO_OPTIONS=DeleteSizeMismatch=0     %run %t baddel     2>&1
5 // RUN: SCUDO_OPTIONS=DeleteSizeMismatch=1     %run %t gooddelarr 2>&1
6 // RUN: SCUDO_OPTIONS=DeleteSizeMismatch=1 not %run %t baddelarr  2>&1 | FileCheck %s
7 // RUN: SCUDO_OPTIONS=DeleteSizeMismatch=0     %run %t baddelarr  2>&1
8 
9 // Ensures that the sized delete operator errors out when the appropriate
10 // option is passed and the sizes do not match between allocation and
11 // deallocation functions.
12 
13 #include <new>
14 #include <assert.h>
15 #include <stdlib.h>
16 #include <string.h>
17 
main(int argc,char ** argv)18 int main(int argc, char **argv)
19 {
20   assert(argc == 2);
21   if (!strcmp(argv[1], "gooddel")) {
22     long long *p = new long long;
23     operator delete(p, sizeof(long long));
24   }
25   if (!strcmp(argv[1], "baddel")) {
26     long long *p = new long long;
27     operator delete(p, 2);
28   }
29   if (!strcmp(argv[1], "gooddelarr")) {
30     char *p = new char[64];
31     operator delete[](p, 64);
32   }
33   if (!strcmp(argv[1], "baddelarr")) {
34     char *p = new char[63];
35     operator delete[](p, 64);
36   }
37   return 0;
38 }
39 
40 // CHECK: ERROR: invalid sized delete on chunk at address
41