https://llvm.org/bugs/show_bug.cgi?id=26812
Bug ID: 26812 Summary: possible overflow issue in std::allocator::allocate Product: libc++ Version: 3.8 Hardware: PC OS: All Status: NEW Severity: normal Priority: P Component: All Bugs Assignee: unassignedclangb...@nondot.org Reporter: ionelpopesc...@yahoo.com CC: llvm-bugs@lists.llvm.org, mclow.li...@gmail.com Classification: Unclassified std::allocator::allocate is currently implemented like this: _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0) {return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));} If __n > allocator::max_size() this will cause an overflow ant the result will not be throwing a std::bad_alloc, but instead it will allocate a size determined by overflow. It should be better implemented like this: _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0) { if (__n > max_size()) { #ifndef _LIBCPP_NO_EXCEPTIONS throw std::bad_alloc(); #endif } return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp))); } -- You are receiving this mail because: You are on the CC list for the bug.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs