Reviewed By: serge-sans-paille
Differential Revision: https://reviews.llvm.org/D121399
StringRef NameRef = BufferName.toStringRef(NameBuf);
size_t AlignedStringLen = alignTo(sizeof(MemBuffer) + NameRef.size() + 1, 16);
size_t RealLen = AlignedStringLen + Size + 1;
+ if (RealLen <= Size) // Check for rollover.
+ return nullptr;
char *Mem = static_cast<char*>(operator new(RealLen, std::nothrow));
if (!Mem)
return nullptr;
EXPECT_NE(nullptr, Four.get());
for (size_t i = 0; i < 123; ++i)
EXPECT_EQ(0, Four->getBufferStart()[0]);
+
+ // uninitialized buffer with rollover size
+ OwningBuffer Five(
+ WritableMemoryBuffer::getNewUninitMemBuffer(SIZE_MAX, "huge"));
+ EXPECT_EQ(nullptr, Five.get());
}
void MemoryBufferTest::testGetOpenFileSlice(bool Reopen) {