summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/asan/tests/asan_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'compiler-rt/lib/asan/tests/asan_test.cc')
-rw-r--r--compiler-rt/lib/asan/tests/asan_test.cc18
1 files changed, 14 insertions, 4 deletions
diff --git a/compiler-rt/lib/asan/tests/asan_test.cc b/compiler-rt/lib/asan/tests/asan_test.cc
index 5ae525de987..6071dce66a8 100644
--- a/compiler-rt/lib/asan/tests/asan_test.cc
+++ b/compiler-rt/lib/asan/tests/asan_test.cc
@@ -227,16 +227,26 @@ TEST(AddressSanitizer, BitFieldNegativeTest) {
delete Ident(x);
}
+static size_t kOOMAllocationSize =
+ SANITIZER_WORDSIZE == 64 ? (size_t)(1ULL << 48) : (0xf0000000);
+
TEST(AddressSanitizer, OutOfMemoryTest) {
- size_t size = SANITIZER_WORDSIZE == 64 ? (size_t)(1ULL << 48) : (0xf0000000);
- EXPECT_EQ(0, realloc(0, size));
+ EXPECT_EQ(0, realloc(0, kOOMAllocationSize));
EXPECT_EQ(0, realloc(0, ~Ident(0)));
- EXPECT_EQ(0, malloc(size));
+ EXPECT_EQ(0, malloc(kOOMAllocationSize));
EXPECT_EQ(0, malloc(~Ident(0)));
- EXPECT_EQ(0, calloc(1, size));
+ EXPECT_EQ(0, calloc(1, kOOMAllocationSize));
EXPECT_EQ(0, calloc(1, ~Ident(0)));
}
+TEST(AddressSanitizer, BadReallocTest) {
+ int *a = (int*)Ident(malloc(100));
+ a[0] = 42;
+ EXPECT_EQ(0, realloc(a, kOOMAllocationSize));
+ EXPECT_EQ(42, a[0]);
+ free(a);
+}
+
#if ASAN_NEEDS_SEGV
namespace {
OpenPOWER on IntegriCloud