@@ -974,25 +974,26 @@ Status MinidumpFileBuilder::ReadWriteMemoryInChunks(
974
974
const lldb_private::CoreFileMemoryRange &range, uint64_t *bytes_read) {
975
975
if (!data_up)
976
976
return Status::FromErrorString (" No buffer supplied to read memory." );
977
+
978
+ if (!bytes_read)
979
+ return Status::FromErrorString (" Bytes read pointer cannot be null." );
977
980
Log *log = GetLog (LLDBLog::Object);
978
981
const lldb::addr_t addr = range.range .start ();
979
982
const lldb::addr_t size = range.range .size ();
980
983
// First we set the byte tally to 0, so if we do exit gracefully
981
984
// the caller doesn't think the random garbage on the stack is a
982
985
// success.
983
- if (bytes_read)
984
- *bytes_read = 0 ;
986
+ *bytes_read = 0 ;
985
987
986
988
uint64_t bytes_remaining = size;
987
- uint64_t total_bytes_read = 0 ;
988
989
Status error;
989
990
while (bytes_remaining > 0 ) {
990
991
// Get the next read chunk size as the minimum of the remaining bytes and
991
992
// the write chunk max size.
992
993
const size_t bytes_to_read =
993
- std::min (bytes_remaining, MAX_WRITE_CHUNK_SIZE );
994
+ std::min (bytes_remaining, data_up-> GetByteSize () );
994
995
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 ,
996
997
data_up->GetBytes (), bytes_to_read, error);
997
998
if (error.Fail () || bytes_read_for_chunk == 0 ) {
998
999
LLDB_LOGF (log,
@@ -1001,7 +1002,7 @@ Status MinidumpFileBuilder::ReadWriteMemoryInChunks(
1001
1002
addr, bytes_read_for_chunk, error.AsCString ());
1002
1003
// If we've read nothing, and get an error or fail to read
1003
1004
// we can just give up early.
1004
- if (total_bytes_read == 0 )
1005
+ if (*bytes_read == 0 )
1005
1006
return Status ();
1006
1007
1007
1008
// If we've read some bytes, we stop trying to read more and return
@@ -1036,12 +1037,10 @@ Status MinidumpFileBuilder::ReadWriteMemoryInChunks(
1036
1037
if (bytes_remaining > 0 )
1037
1038
bytes_remaining -= bytes_read_for_chunk;
1038
1039
1039
- total_bytes_read += bytes_read_for_chunk;
1040
1040
// If the caller wants a tally back of the bytes_read, update it as we
1041
1041
// write. We do this in the loop so if we encounter an error we can
1042
1042
// report the accurate total.
1043
- if (bytes_read)
1044
- *bytes_read += bytes_read_for_chunk;
1043
+ *bytes_read += bytes_read_for_chunk;
1045
1044
}
1046
1045
1047
1046
return error;
0 commit comments