mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-04-28 15:28:38 +00:00
VolumeDirectory: Don't use references inappropriately
Integers should be passed as pointers when a function modifies them (to make it clear that they get modified).
This commit is contained in:
parent
9c8e27e3bb
commit
00aa2d37e9
2 changed files with 55 additions and 56 deletions
|
@ -79,30 +79,30 @@ bool CVolumeDirectory::Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt
|
||||||
// header
|
// header
|
||||||
if (_Offset < DISKHEADERINFO_ADDRESS)
|
if (_Offset < DISKHEADERINFO_ADDRESS)
|
||||||
{
|
{
|
||||||
WriteToBuffer(DISKHEADER_ADDRESS, DISKHEADERINFO_ADDRESS, m_diskHeader.data(), _Offset, _Length,
|
WriteToBuffer(DISKHEADER_ADDRESS, DISKHEADERINFO_ADDRESS, m_diskHeader.data(), &_Offset,
|
||||||
_pBuffer);
|
&_Length, &_pBuffer);
|
||||||
}
|
}
|
||||||
// header info
|
// header info
|
||||||
if (_Offset >= DISKHEADERINFO_ADDRESS && _Offset < APPLOADER_ADDRESS)
|
if (_Offset >= DISKHEADERINFO_ADDRESS && _Offset < APPLOADER_ADDRESS)
|
||||||
{
|
{
|
||||||
WriteToBuffer(DISKHEADERINFO_ADDRESS, sizeof(m_diskHeaderInfo), (u8*)m_diskHeaderInfo.get(),
|
WriteToBuffer(DISKHEADERINFO_ADDRESS, sizeof(m_diskHeaderInfo), (u8*)m_diskHeaderInfo.get(),
|
||||||
_Offset, _Length, _pBuffer);
|
&_Offset, &_Length, &_pBuffer);
|
||||||
}
|
}
|
||||||
// apploader
|
// apploader
|
||||||
if (_Offset >= APPLOADER_ADDRESS && _Offset < APPLOADER_ADDRESS + m_apploader.size())
|
if (_Offset >= APPLOADER_ADDRESS && _Offset < APPLOADER_ADDRESS + m_apploader.size())
|
||||||
{
|
{
|
||||||
WriteToBuffer(APPLOADER_ADDRESS, m_apploader.size(), m_apploader.data(), _Offset, _Length,
|
WriteToBuffer(APPLOADER_ADDRESS, m_apploader.size(), m_apploader.data(), &_Offset, &_Length,
|
||||||
_pBuffer);
|
&_pBuffer);
|
||||||
}
|
}
|
||||||
// dol
|
// dol
|
||||||
if (_Offset >= m_dol_address && _Offset < m_dol_address + m_DOL.size())
|
if (_Offset >= m_dol_address && _Offset < m_dol_address + m_DOL.size())
|
||||||
{
|
{
|
||||||
WriteToBuffer(m_dol_address, m_DOL.size(), m_DOL.data(), _Offset, _Length, _pBuffer);
|
WriteToBuffer(m_dol_address, m_DOL.size(), m_DOL.data(), &_Offset, &_Length, &_pBuffer);
|
||||||
}
|
}
|
||||||
// fst
|
// fst
|
||||||
if (_Offset >= m_fst_address && _Offset < m_dataStartAddress)
|
if (_Offset >= m_fst_address && _Offset < m_dataStartAddress)
|
||||||
{
|
{
|
||||||
WriteToBuffer(m_fst_address, m_FSTData.size(), m_FSTData.data(), _Offset, _Length, _pBuffer);
|
WriteToBuffer(m_fst_address, m_FSTData.size(), m_FSTData.data(), &_Offset, &_Length, &_pBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_virtualDisk.empty())
|
if (m_virtualDisk.empty())
|
||||||
|
@ -114,7 +114,7 @@ bool CVolumeDirectory::Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt
|
||||||
--fileIter;
|
--fileIter;
|
||||||
|
|
||||||
// zero fill to start of file data
|
// zero fill to start of file data
|
||||||
PadToAddress(fileIter->first, _Offset, _Length, _pBuffer);
|
PadToAddress(fileIter->first, &_Offset, &_Length, &_pBuffer);
|
||||||
|
|
||||||
while (fileIter != m_virtualDisk.end() && _Length > 0)
|
while (fileIter != m_virtualDisk.end() && _Length > 0)
|
||||||
{
|
{
|
||||||
|
@ -149,7 +149,7 @@ bool CVolumeDirectory::Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt
|
||||||
if (fileIter != m_virtualDisk.end())
|
if (fileIter != m_virtualDisk.end())
|
||||||
{
|
{
|
||||||
_dbg_assert_(DVDINTERFACE, fileIter->first >= _Offset);
|
_dbg_assert_(DVDINTERFACE, fileIter->first >= _Offset);
|
||||||
PadToAddress(fileIter->first, _Offset, _Length, _pBuffer);
|
PadToAddress(fileIter->first, &_Offset, &_Length, &_pBuffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,9 +361,9 @@ void CVolumeDirectory::BuildFST()
|
||||||
u32 rootOffset = 0; // Offset of root of FST
|
u32 rootOffset = 0; // Offset of root of FST
|
||||||
|
|
||||||
// write root entry
|
// write root entry
|
||||||
WriteEntryData(fstOffset, DIRECTORY_ENTRY, 0, 0, rootEntry.size);
|
WriteEntryData(&fstOffset, DIRECTORY_ENTRY, 0, 0, rootEntry.size);
|
||||||
|
|
||||||
WriteDirectory(rootEntry, fstOffset, nameOffset, curDataAddress, rootOffset);
|
WriteDirectory(rootEntry, &fstOffset, &nameOffset, &curDataAddress, rootOffset);
|
||||||
|
|
||||||
// overflow check
|
// overflow check
|
||||||
_dbg_assert_(DVDINTERFACE, nameOffset == name_table_size);
|
_dbg_assert_(DVDINTERFACE, nameOffset == name_table_size);
|
||||||
|
@ -375,37 +375,37 @@ void CVolumeDirectory::BuildFST()
|
||||||
}
|
}
|
||||||
|
|
||||||
void CVolumeDirectory::WriteToBuffer(u64 _SrcStartAddress, u64 _SrcLength, const u8* _Src,
|
void CVolumeDirectory::WriteToBuffer(u64 _SrcStartAddress, u64 _SrcLength, const u8* _Src,
|
||||||
u64& _Address, u64& _Length, u8*& _pBuffer) const
|
u64* _Address, u64* _Length, u8** _pBuffer) const
|
||||||
{
|
{
|
||||||
if (_Length == 0)
|
if (*_Length == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_dbg_assert_(DVDINTERFACE, _Address >= _SrcStartAddress);
|
_dbg_assert_(DVDINTERFACE, *_Address >= _SrcStartAddress);
|
||||||
|
|
||||||
u64 srcOffset = _Address - _SrcStartAddress;
|
u64 srcOffset = *_Address - _SrcStartAddress;
|
||||||
|
|
||||||
if (srcOffset < _SrcLength)
|
if (srcOffset < _SrcLength)
|
||||||
{
|
{
|
||||||
u64 srcBytes = std::min(_SrcLength - srcOffset, _Length);
|
u64 srcBytes = std::min(_SrcLength - srcOffset, *_Length);
|
||||||
|
|
||||||
memcpy(_pBuffer, _Src + srcOffset, (size_t)srcBytes);
|
memcpy(*_pBuffer, _Src + srcOffset, (size_t)srcBytes);
|
||||||
|
|
||||||
_Length -= srcBytes;
|
*_Length -= srcBytes;
|
||||||
_pBuffer += srcBytes;
|
*_pBuffer += srcBytes;
|
||||||
_Address += srcBytes;
|
*_Address += srcBytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CVolumeDirectory::PadToAddress(u64 _StartAddress, u64& _Address, u64& _Length,
|
void CVolumeDirectory::PadToAddress(u64 _StartAddress, u64* _Address, u64* _Length,
|
||||||
u8*& _pBuffer) const
|
u8** _pBuffer) const
|
||||||
{
|
{
|
||||||
if (_StartAddress > _Address && _Length > 0)
|
if (_StartAddress > *_Address && *_Length > 0)
|
||||||
{
|
{
|
||||||
u64 padBytes = std::min(_StartAddress - _Address, _Length);
|
u64 padBytes = std::min(_StartAddress - *_Address, *_Length);
|
||||||
memset(_pBuffer, 0, (size_t)padBytes);
|
memset(*_pBuffer, 0, (size_t)padBytes);
|
||||||
_Length -= padBytes;
|
*_Length -= padBytes;
|
||||||
_pBuffer += padBytes;
|
*_pBuffer += padBytes;
|
||||||
_Address += padBytes;
|
*_Address += padBytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,31 +417,31 @@ void CVolumeDirectory::Write32(u32 data, u32 offset, std::vector<u8>* const buff
|
||||||
(*buffer)[offset] = (data)&0xff;
|
(*buffer)[offset] = (data)&0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CVolumeDirectory::WriteEntryData(u32& entryOffset, u8 type, u32 nameOffset, u64 dataOffset,
|
void CVolumeDirectory::WriteEntryData(u32* entryOffset, u8 type, u32 nameOffset, u64 dataOffset,
|
||||||
u64 length)
|
u64 length)
|
||||||
{
|
{
|
||||||
m_FSTData[entryOffset++] = type;
|
m_FSTData[(*entryOffset)++] = type;
|
||||||
|
|
||||||
m_FSTData[entryOffset++] = (nameOffset >> 16) & 0xff;
|
m_FSTData[(*entryOffset)++] = (nameOffset >> 16) & 0xff;
|
||||||
m_FSTData[entryOffset++] = (nameOffset >> 8) & 0xff;
|
m_FSTData[(*entryOffset)++] = (nameOffset >> 8) & 0xff;
|
||||||
m_FSTData[entryOffset++] = (nameOffset)&0xff;
|
m_FSTData[(*entryOffset)++] = (nameOffset)&0xff;
|
||||||
|
|
||||||
Write32((u32)(dataOffset >> m_addressShift), entryOffset, &m_FSTData);
|
Write32((u32)(dataOffset >> m_addressShift), *entryOffset, &m_FSTData);
|
||||||
entryOffset += 4;
|
*entryOffset += 4;
|
||||||
|
|
||||||
Write32((u32)length, entryOffset, &m_FSTData);
|
Write32((u32)length, *entryOffset, &m_FSTData);
|
||||||
entryOffset += 4;
|
*entryOffset += 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CVolumeDirectory::WriteEntryName(u32& nameOffset, const std::string& name)
|
void CVolumeDirectory::WriteEntryName(u32* nameOffset, const std::string& name)
|
||||||
{
|
{
|
||||||
strncpy((char*)&m_FSTData[nameOffset + m_fstNameOffset], name.c_str(), name.length() + 1);
|
strncpy((char*)&m_FSTData[*nameOffset + m_fstNameOffset], name.c_str(), name.length() + 1);
|
||||||
|
|
||||||
nameOffset += (u32)(name.length() + 1);
|
*nameOffset += (u32)(name.length() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CVolumeDirectory::WriteDirectory(const File::FSTEntry& parent_entry, u32& fstOffset,
|
void CVolumeDirectory::WriteDirectory(const File::FSTEntry& parent_entry, u32* fstOffset,
|
||||||
u32& nameOffset, u64& dataOffset, u32 parentEntryNum)
|
u32* nameOffset, u64* dataOffset, u32 parentEntryNum)
|
||||||
{
|
{
|
||||||
std::vector<File::FSTEntry> sorted_entries = parent_entry.children;
|
std::vector<File::FSTEntry> sorted_entries = parent_entry.children;
|
||||||
|
|
||||||
|
@ -454,9 +454,8 @@ void CVolumeDirectory::WriteDirectory(const File::FSTEntry& parent_entry, u32& f
|
||||||
{
|
{
|
||||||
if (entry.isDirectory)
|
if (entry.isDirectory)
|
||||||
{
|
{
|
||||||
u32 myOffset = fstOffset;
|
u32 myEntryNum = *fstOffset / ENTRY_SIZE;
|
||||||
u32 myEntryNum = myOffset / ENTRY_SIZE;
|
WriteEntryData(fstOffset, DIRECTORY_ENTRY, *nameOffset, parentEntryNum,
|
||||||
WriteEntryData(fstOffset, DIRECTORY_ENTRY, nameOffset, parentEntryNum,
|
|
||||||
myEntryNum + entry.size + 1);
|
myEntryNum + entry.size + 1);
|
||||||
WriteEntryName(nameOffset, entry.virtualName);
|
WriteEntryName(nameOffset, entry.virtualName);
|
||||||
|
|
||||||
|
@ -465,15 +464,15 @@ void CVolumeDirectory::WriteDirectory(const File::FSTEntry& parent_entry, u32& f
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// put entry in FST
|
// put entry in FST
|
||||||
WriteEntryData(fstOffset, FILE_ENTRY, nameOffset, dataOffset, entry.size);
|
WriteEntryData(fstOffset, FILE_ENTRY, *nameOffset, *dataOffset, entry.size);
|
||||||
WriteEntryName(nameOffset, entry.virtualName);
|
WriteEntryName(nameOffset, entry.virtualName);
|
||||||
|
|
||||||
// write entry to virtual disk
|
// write entry to virtual disk
|
||||||
_dbg_assert_(DVDINTERFACE, m_virtualDisk.find(dataOffset) == m_virtualDisk.end());
|
_dbg_assert_(DVDINTERFACE, m_virtualDisk.find(*dataOffset) == m_virtualDisk.end());
|
||||||
m_virtualDisk.emplace(dataOffset, entry.physicalName);
|
m_virtualDisk.emplace(*dataOffset, entry.physicalName);
|
||||||
|
|
||||||
// 4 byte aligned
|
// 4 byte aligned
|
||||||
dataOffset = Common::AlignUp(dataOffset + std::max<u64>(entry.size, 1ull), 0x8000ull);
|
*dataOffset = Common::AlignUp(*dataOffset + std::max<u64>(entry.size, 1ull), 0x8000ull);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,18 +75,18 @@ private:
|
||||||
void SetDOL(const std::string& _rDOL);
|
void SetDOL(const std::string& _rDOL);
|
||||||
|
|
||||||
// writing to read buffer
|
// writing to read buffer
|
||||||
void WriteToBuffer(u64 _SrcStartAddress, u64 _SrcLength, const u8* _Src, u64& _Address,
|
void WriteToBuffer(u64 _SrcStartAddress, u64 _SrcLength, const u8* _Src, u64* _Address,
|
||||||
u64& _Length, u8*& _pBuffer) const;
|
u64* _Length, u8** _pBuffer) const;
|
||||||
|
|
||||||
void PadToAddress(u64 _StartAddress, u64& _Address, u64& _Length, u8*& _pBuffer) const;
|
void PadToAddress(u64 _StartAddress, u64* _Address, u64* _Length, u8** _pBuffer) const;
|
||||||
|
|
||||||
void Write32(u32 data, u32 offset, std::vector<u8>* const buffer);
|
void Write32(u32 data, u32 offset, std::vector<u8>* const buffer);
|
||||||
|
|
||||||
// FST creation
|
// FST creation
|
||||||
void WriteEntryData(u32& entryOffset, u8 type, u32 nameOffset, u64 dataOffset, u64 length);
|
void WriteEntryData(u32* entryOffset, u8 type, u32 nameOffset, u64 dataOffset, u64 length);
|
||||||
void WriteEntryName(u32& nameOffset, const std::string& name);
|
void WriteEntryName(u32* nameOffset, const std::string& name);
|
||||||
void WriteDirectory(const File::FSTEntry& parent_entry, u32& fstOffset, u32& nameOffset,
|
void WriteDirectory(const File::FSTEntry& parent_entry, u32* fstOffset, u32* nameOffset,
|
||||||
u64& dataOffset, u32 parentEntryNum);
|
u64* dataOffset, u32 parentEntryNum);
|
||||||
|
|
||||||
std::string m_rootDirectory;
|
std::string m_rootDirectory;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue