diff options
| author | Marshall Clow <mclow.lists@gmail.com> | 2016-03-03 12:04:39 +0000 |
|---|---|---|
| committer | Marshall Clow <mclow.lists@gmail.com> | 2016-03-03 12:04:39 +0000 |
| commit | 4cec709ed60a7ffdea782edfdddc269c274decf2 (patch) | |
| tree | 5ec19f2dca87ba19a5f3bf4d779910eec4aa9fcd /libcxx/test/std | |
| parent | 1ad03e7f01124041865000cccc99b54f0a2e853a (diff) | |
| download | bcm5719-llvm-4cec709ed60a7ffdea782edfdddc269c274decf2.tar.gz bcm5719-llvm-4cec709ed60a7ffdea782edfdddc269c274decf2.zip | |
Fix for PR26812: possible overflow issue in std::allocator::allocate
llvm-svn: 262610
Diffstat (limited to 'libcxx/test/std')
| -rw-r--r-- | libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp b/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp new file mode 100644 index 00000000000..4846b0a496b --- /dev/null +++ b/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// allocator: +// pointer allocate(size_type n, allocator<void>::const_pointer hint=0); + +#include <memory> +#include <cassert> + +template <typename T> +void test_max(size_t count) +{ + std::allocator<T> a; + try { a.allocate( count ); } + catch ( const std::bad_alloc &) { return ; } + assert (false); +} + +int main() +{ + { // Bug 26812 -- allocating too large + typedef double T; + std::allocator<T> a; + test_max<T> (a.max_size() + 1); // just barely too large + test_max<T> (a.max_size() * 2); // significantly too large + test_max<T> (((size_t) -1) / sizeof(T) + 1); // multiply will overflow + test_max<T> ((size_t) -1); // way too large + } + + { + typedef const double T; + std::allocator<T> a; + test_max<T> (a.max_size() + 1); // just barely too large + test_max<T> (a.max_size() * 2); // significantly too large + test_max<T> (((size_t) -1) / sizeof(T) + 1); // multiply will overflow + test_max<T> ((size_t) -1); // way too large + } +} |

