From 11023dc647fd8f41418da90d59db138400d0f334 Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Mon, 27 May 2013 18:27:12 +0000 Subject: Import compiler-rt r182741. --- lib/tsan/lit_tests/malloc_overflow.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 lib/tsan/lit_tests/malloc_overflow.cc (limited to 'lib/tsan/lit_tests/malloc_overflow.cc') diff --git a/lib/tsan/lit_tests/malloc_overflow.cc b/lib/tsan/lit_tests/malloc_overflow.cc new file mode 100644 index 0000000000000..19423c5f93f14 --- /dev/null +++ b/lib/tsan/lit_tests/malloc_overflow.cc @@ -0,0 +1,22 @@ +// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s +#include +#include + +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 -- cgit v1.2.3