diff options
Diffstat (limited to 'llvm/lib/Support/SmallVector.cpp')
-rw-r--r-- | llvm/lib/Support/SmallVector.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/llvm/lib/Support/SmallVector.cpp b/llvm/lib/Support/SmallVector.cpp index 36f0a81..9ece0c5 100644 --- a/llvm/lib/Support/SmallVector.cpp +++ b/llvm/lib/Support/SmallVector.cpp @@ -39,12 +39,19 @@ static_assert(sizeof(SmallVector<void *, 1>) == /// grow_pod - This is an implementation of the grow() method which only works /// on POD-like datatypes and is out of line to reduce code duplication. +/// This function will report a fatal error if it cannot increase capacity. void SmallVectorBase::grow_pod(void *FirstEl, size_t MinCapacity, size_t TSize) { // Ensure we can fit the new capacity in 32 bits. if (MinCapacity > UINT32_MAX) report_bad_alloc_error("SmallVector capacity overflow during allocation"); + // Ensure we can meet the guarantee of space for at least one more element. + // The above check alone will not catch the case where grow is called with a + // default MinCapacity of 0, but the current capacity cannot be increased. + if (capacity() == size_t(UINT32_MAX)) + report_bad_alloc_error("SmallVector capacity unable to grow"); + size_t NewCapacity = 2 * capacity() + 1; // Always grow. NewCapacity = std::min(std::max(NewCapacity, MinCapacity), size_t(UINT32_MAX)); |