| OLD | NEW |
| 1 // Copyright (c) 2005, Google Inc. | 1 // Copyright (c) 2005, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 |
| 30 // --- | 30 // --- |
| 31 // Author: Michael Chastain | 31 // Author: Michael Chastain |
| 32 // | 32 // |
| 33 // This is a unit test for large allocations in malloc and friends. | 33 // This is a unit test for large allocations in malloc and friends. |
| 34 // "Large" means "so large that they overflow the address space". | 34 // "Large" means "so large that they overflow the address space". |
| 35 // For 32 bits, this means allocations near 2^32 bytes and 2^31 bytes. | 35 // For 32 bits, this means allocations near 2^32 bytes and 2^31 bytes. |
| 36 // For 64 bits, this means allocations near 2^64 bytes and 2^63 bytes. | 36 // For 64 bits, this means allocations near 2^64 bytes and 2^63 bytes. |
| 37 | 37 |
| 38 #include <stddef.h> | 38 #include <stddef.h> // for size_t, NULL |
| 39 #include <stdlib.h> | 39 #include <stdlib.h> // for malloc, free, realloc |
| 40 #include <stdio.h> | 40 #include <stdio.h> |
| 41 #include <set> | 41 #include <set> // for set, etc |
| 42 | 42 |
| 43 #include "base/logging.h" | 43 #include "base/logging.h" // for operator<<, CHECK, etc |
| 44 | 44 |
| 45 using std::set; | 45 using std::set; |
| 46 | 46 |
| 47 // Alloc a size that should always fail. | 47 // Alloc a size that should always fail. |
| 48 | 48 |
| 49 void TryAllocExpectFail(size_t size) { | 49 void TryAllocExpectFail(size_t size) { |
| 50 void* p1 = malloc(size); | 50 void* p1 = malloc(size); |
| 51 CHECK(p1 == NULL); | 51 CHECK(p1 == NULL); |
| 52 | 52 |
| 53 void* p2 = malloc(1); | 53 void* p2 = malloc(1); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 static const size_t kHalfPlusMinusTimes = 64; | 128 static const size_t kHalfPlusMinusTimes = 64; |
| 129 const size_t half = (zero - 2) / 2 + 1; | 129 const size_t half = (zero - 2) / 2 + 1; |
| 130 for ( size_t i = 0; i < kHalfPlusMinusTimes; ++i) { | 130 for ( size_t i = 0; i < kHalfPlusMinusTimes; ++i) { |
| 131 TryAllocMightFail(half - i); | 131 TryAllocMightFail(half - i); |
| 132 TryAllocMightFail(half + i); | 132 TryAllocMightFail(half + i); |
| 133 } | 133 } |
| 134 | 134 |
| 135 printf("PASS\n"); | 135 printf("PASS\n"); |
| 136 return 0; | 136 return 0; |
| 137 } | 137 } |
| OLD | NEW |