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/include | |
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/include')
-rw-r--r-- | libcxx/include/memory | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/libcxx/include/memory b/libcxx/include/memory index 281c59eb4c3..67f2fc53ad5 100644 --- a/libcxx/include/memory +++ b/libcxx/include/memory @@ -1726,7 +1726,15 @@ public: _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT {return _VSTD::addressof(__x);} _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0) - {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));} + { + if (__n > max_size()) +#ifndef _LIBCPP_NO_EXCEPTIONS + throw bad_alloc(); +#else + assert(!"allocator<T>::allocate::bad_alloc"); +#endif + return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp))); + } _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT {_VSTD::__deallocate((void*)__p);} _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT @@ -1817,7 +1825,15 @@ public: _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT {return _VSTD::addressof(__x);} _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0) - {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));} + { + if (__n > max_size()) +#ifndef _LIBCPP_NO_EXCEPTIONS + throw bad_alloc(); +#else + assert(!"allocator<const T>::allocate::bad_alloc"); +#endif + return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp))); + } _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT {_VSTD::__deallocate((void*)__p);} _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT |