Skip to content

Commit b7e7a98

Browse files
committed
[lldb] Check max_size before resizing DataBufferHeap
Don't resize DataBufferHeap if the newly requested size exceeds the capacity of the underlying data structure, i.e. std::vector<uint8_t>. This matches the existing check in the DataBufferHeap constructor.
1 parent 2aed90b commit b7e7a98

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lldb/include/lldb/Utility/DataBufferHeap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ class DataBufferHeap : public DataBuffer {
8080
/// to resize itself to.
8181
///
8282
/// \return
83-
/// The size in bytes after that this heap buffer was
84-
/// successfully resized to.
83+
/// The size in bytes after this heap buffer was resized. If
84+
/// the resize failed the size will remain unchanged.
8585
lldb::offset_t SetByteSize(lldb::offset_t byte_size);
8686

8787
/// Makes a copy of the \a src_len bytes in \a src.

lldb/source/Utility/DataBufferHeap.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ uint64_t DataBufferHeap::GetByteSize() const { return m_data.size(); }
4747
// Sets the number of bytes that this object should be able to contain. This
4848
// can be used prior to copying data into the buffer.
4949
uint64_t DataBufferHeap::SetByteSize(uint64_t new_size) {
50-
m_data.resize(new_size);
50+
if (new_size < m_data.max_size())
51+
m_data.resize(new_size);
5152
return m_data.size();
5253
}
5354

0 commit comments

Comments
 (0)