| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #define _CRT_SECURE_NO_WARNINGS | 5 #define _CRT_SECURE_NO_WARNINGS |
| 6 | 6 |
| 7 #include "base/process/memory.h" | 7 #include "base/process/memory.h" |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 #if ARCH_CPU_64_BITS | 143 #if ARCH_CPU_64_BITS |
| 144 // On 64 bit Macs, the malloc system automatically abort()s on heap corruption | 144 // On 64 bit Macs, the malloc system automatically abort()s on heap corruption |
| 145 // but does not output anything. | 145 // but does not output anything. |
| 146 ASSERT_DEATH(free(buf), ""); | 146 ASSERT_DEATH(free(buf), ""); |
| 147 #elif defined(ADDRESS_SANITIZER) | 147 #elif defined(ADDRESS_SANITIZER) |
| 148 // AddressSanitizer replaces malloc() and prints a different error message on | 148 // AddressSanitizer replaces malloc() and prints a different error message on |
| 149 // heap corruption. | 149 // heap corruption. |
| 150 ASSERT_DEATH(free(buf), "attempting free on address which " | 150 ASSERT_DEATH(free(buf), "attempting free on address which " |
| 151 "was not malloc\\(\\)-ed"); | 151 "was not malloc\\(\\)-ed"); |
| 152 #else | 152 #else |
| 153 ASSERT_DEATH(free(buf), "being freed.*\\n?\\.*" | 153 ADD_FAILURE() << "This test is not supported in this build configuration."; |
| 154 "\\*\\*\\* set a breakpoint in malloc_error_break to debug.*\\n?.*" | 154 #endif |
| 155 "Terminating process due to a potential for future heap corruption"); | |
| 156 #endif // ARCH_CPU_64_BITS || defined(ADDRESS_SANITIZER) | |
| 157 } | 155 } |
| 158 | 156 |
| 159 #endif // defined(OS_MACOSX) | 157 #endif // defined(OS_MACOSX) |
| 160 | 158 |
| 161 // Android doesn't implement set_new_handler, so we can't use the | 159 // Android doesn't implement set_new_handler, so we can't use the |
| 162 // OutOfMemoryTest cases. | 160 // OutOfMemoryTest cases. |
| 163 // OpenBSD does not support these tests either. | 161 // OpenBSD does not support these tests either. |
| 164 // TODO(vandebo) make this work on Windows too. | 162 // TODO(vandebo) make this work on Windows too. |
| 165 #if !defined(OS_ANDROID) && !defined(OS_OPENBSD) && \ | 163 #if !defined(OS_ANDROID) && !defined(OS_OPENBSD) && \ |
| 166 !defined(OS_WIN) | 164 !defined(OS_WIN) |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 bytes = static_cast<const char*>(value_); | 436 bytes = static_cast<const char*>(value_); |
| 439 for (size_t i = 0; i < (kSafeCallocItems * kSafeCallocSize); ++i) | 437 for (size_t i = 0; i < (kSafeCallocItems * kSafeCallocSize); ++i) |
| 440 EXPECT_EQ(0, bytes[i]); | 438 EXPECT_EQ(0, bytes[i]); |
| 441 free(value_); | 439 free(value_); |
| 442 | 440 |
| 443 EXPECT_FALSE(base::UncheckedCalloc(1, test_size_, &value_)); | 441 EXPECT_FALSE(base::UncheckedCalloc(1, test_size_, &value_)); |
| 444 EXPECT_TRUE(value_ == NULL); | 442 EXPECT_TRUE(value_ == NULL); |
| 445 } | 443 } |
| 446 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) | 444 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |
| 447 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && !defined(OS_WIN) | 445 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && !defined(OS_WIN) |
| OLD | NEW |