1 // RUN: %clangxx_scudo -fsized-deallocation %s -o %t
2 // RUN: %env_scudo_opts=DeleteSizeMismatch=1 %run %t gooddel 2>&1
3 // RUN: %env_scudo_opts=DeleteSizeMismatch=1 not %run %t baddel 2>&1 | FileCheck %s
4 // RUN: %env_scudo_opts=DeleteSizeMismatch=0 %run %t baddel 2>&1
5 // RUN: %env_scudo_opts=DeleteSizeMismatch=1 %run %t gooddelarr 2>&1
6 // RUN: %env_scudo_opts=DeleteSizeMismatch=1 not %run %t baddelarr 2>&1 | FileCheck %s
7 // RUN: %env_scudo_opts=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 <assert.h>
14 #include <stdlib.h>
15 #include <string.h>
16
17 #include <new>
18
main(int argc,char ** argv)19 int main(int argc, char **argv)
20 {
21 assert(argc == 2);
22 if (!strcmp(argv[1], "gooddel")) {
23 long long *p = new long long;
24 operator delete(p, sizeof(long long));
25 }
26 if (!strcmp(argv[1], "baddel")) {
27 long long *p = new long long;
28 operator delete(p, 2);
29 }
30 if (!strcmp(argv[1], "gooddelarr")) {
31 char *p = new char[64];
32 operator delete[](p, 64);
33 }
34 if (!strcmp(argv[1], "baddelarr")) {
35 char *p = new char[63];
36 operator delete[](p, 64);
37 }
38 return 0;
39 }
40
41 // CHECK: ERROR: invalid sized delete when deallocating address
42