diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2015-01-07 19:55:37 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2015-01-07 19:55:37 +0000 |
commit | ca9211ecdede9bdedb812b2243a4abdb8dacd1b9 (patch) | |
tree | 9b19e801150082c33e9152275829a6ce90614b55 /test/tsan/malloc_overflow.cc | |
parent | 8ef50bf3d1c287b5013c3168de77a462dfce3495 (diff) |
Diffstat (limited to 'test/tsan/malloc_overflow.cc')
-rw-r--r-- | test/tsan/malloc_overflow.cc | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/tsan/malloc_overflow.cc b/test/tsan/malloc_overflow.cc new file mode 100644 index 0000000000000..dadc94484f01e --- /dev/null +++ b/test/tsan/malloc_overflow.cc @@ -0,0 +1,23 @@ +// RUN: %clangxx_tsan -O1 %s -o %t +// RUN: TSAN_OPTIONS=allocator_may_return_null=1 %run %t 2>&1 | FileCheck %s +#include <stdio.h> +#include <stdlib.h> + +int main() { + void *p = malloc((size_t)-1); + if (p != 0) + printf("FAIL malloc(-1) = %p\n", p); + p = malloc((size_t)-1 / 2); + if (p != 0) + printf("FAIL malloc(-1/2) = %p\n", p); + p = calloc((size_t)-1, (size_t)-1); + if (p != 0) + printf("FAIL calloc(-1, -1) = %p\n", p); + p = calloc((size_t)-1 / 2, (size_t)-1 / 2); + if (p != 0) + printf("FAIL calloc(-1/2, -1/2) = %p\n", p); + printf("OK\n"); +} + +// CHECK-NOT: FAIL +// CHECK-NOT: failed to allocate |