Skip to content

Commit dc67f7d

Browse files
committed
Finish refactor of data_up being the max buffer size, and enforce bytes_read* is not null
1 parent f73943b commit dc67f7d

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -974,25 +974,26 @@ Status MinidumpFileBuilder::ReadWriteMemoryInChunks(
974974
const lldb_private::CoreFileMemoryRange &range, uint64_t *bytes_read) {
975975
if (!data_up)
976976
return Status::FromErrorString("No buffer supplied to read memory.");
977+
978+
if (!bytes_read)
979+
return Status::FromErrorString("Bytes read pointer cannot be null.");
977980
Log *log = GetLog(LLDBLog::Object);
978981
const lldb::addr_t addr = range.range.start();
979982
const lldb::addr_t size = range.range.size();
980983
// First we set the byte tally to 0, so if we do exit gracefully
981984
// the caller doesn't think the random garbage on the stack is a
982985
// success.
983-
if (bytes_read)
984-
*bytes_read = 0;
986+
*bytes_read = 0;
985987

986988
uint64_t bytes_remaining = size;
987-
uint64_t total_bytes_read = 0;
988989
Status error;
989990
while (bytes_remaining > 0) {
990991
// Get the next read chunk size as the minimum of the remaining bytes and
991992
// the write chunk max size.
992993
const size_t bytes_to_read =
993-
std::min(bytes_remaining, MAX_WRITE_CHUNK_SIZE);
994+
std::min(bytes_remaining, data_up->GetByteSize());
994995
const size_t bytes_read_for_chunk =
995-
m_process_sp->ReadMemory(range.range.start() + total_bytes_read,
996+
m_process_sp->ReadMemory(range.range.start() + *bytes_read,
996997
data_up->GetBytes(), bytes_to_read, error);
997998
if (error.Fail() || bytes_read_for_chunk == 0) {
998999
LLDB_LOGF(log,
@@ -1001,7 +1002,7 @@ Status MinidumpFileBuilder::ReadWriteMemoryInChunks(
10011002
addr, bytes_read_for_chunk, error.AsCString());
10021003
// If we've read nothing, and get an error or fail to read
10031004
// we can just give up early.
1004-
if (total_bytes_read == 0)
1005+
if (*bytes_read == 0)
10051006
return Status();
10061007

10071008
// If we've read some bytes, we stop trying to read more and return
@@ -1036,12 +1037,10 @@ Status MinidumpFileBuilder::ReadWriteMemoryInChunks(
10361037
if (bytes_remaining > 0)
10371038
bytes_remaining -= bytes_read_for_chunk;
10381039

1039-
total_bytes_read += bytes_read_for_chunk;
10401040
// If the caller wants a tally back of the bytes_read, update it as we
10411041
// write. We do this in the loop so if we encounter an error we can
10421042
// report the accurate total.
1043-
if (bytes_read)
1044-
*bytes_read += bytes_read_for_chunk;
1043+
*bytes_read += bytes_read_for_chunk;
10451044
}
10461045

10471046
return error;

0 commit comments

Comments
 (0)