Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix analysis warnings #20

Merged
merged 1 commit into from
Mar 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions Source/Common/MemoryCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen
break;
}

char* buffer = new char[getSizeForType(type, length)];
size_t size = getSizeForType(type, length);
char* buffer = new char[size];

switch (type)
{
Expand Down Expand Up @@ -141,7 +142,7 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen
theByte = static_cast<u8>(theByteInt);
}

std::memcpy(buffer, &theByte, sizeof(u8));
std::memcpy(buffer, &theByte, size);
actualLength = sizeof(u8);
break;
}
Expand Down Expand Up @@ -177,7 +178,7 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen
}
}

std::memcpy(buffer, &theHalfword, sizeof(u16));
std::memcpy(buffer, &theHalfword, size);
actualLength = sizeof(u16);
break;
}
Expand Down Expand Up @@ -213,7 +214,7 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen
}
}

std::memcpy(buffer, &theWord, sizeof(u32));
std::memcpy(buffer, &theWord, size);
actualLength = sizeof(u32);
break;
}
Expand All @@ -230,7 +231,7 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen
returnCode = MemOperationReturnCode::invalidInput;
return buffer;
}
std::memcpy(buffer, &theFloat, sizeof(float));
std::memcpy(buffer, &theFloat, size);
actualLength = sizeof(float);
break;
}
Expand All @@ -247,7 +248,7 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen
returnCode = MemOperationReturnCode::invalidInput;
return buffer;
}
std::memcpy(buffer, &theDouble, sizeof(double));
std::memcpy(buffer, &theDouble, size);
actualLength = sizeof(double);
break;
}
Expand Down Expand Up @@ -300,7 +301,7 @@ char* formatStringToMemory(MemOperationReturnCode& returnCode, size_t& actualLen
}

int index = 0;
for (auto i : bytes)
for (const auto& i : bytes)
{
std::stringstream byteStream(i);
ss >> std::hex;
Expand Down
8 changes: 4 additions & 4 deletions Source/GUI/MemViewer/MemViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ MemViewer::MemViewer(QWidget* parent) : QAbstractScrollArea(parent)
{
initialise();

std::fill(m_memoryMsElapsedLastChange, m_memoryMsElapsedLastChange + m_numCells, 0);
updateMemoryData();
std::memcpy(m_lastRawMemoryData, m_updatedRawMemoryData, m_numCells);

setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
changeMemoryRegion(false);
verticalScrollBar()->setPageStep(m_numRows);
Expand Down Expand Up @@ -49,6 +45,10 @@ void MemViewer::initialise()
m_memViewStart = Common::MEM1_START;
m_memViewEnd = Common::MEM1_END;
m_currentFirstAddress = m_memViewStart;

std::fill(m_memoryMsElapsedLastChange, m_memoryMsElapsedLastChange + m_numCells, 0);
updateMemoryData();
std::memcpy(m_lastRawMemoryData, m_updatedRawMemoryData, m_numCells);
}

QSize MemViewer::sizeHint() const
Expand Down