From b34f2a78f59fb51425e62c99df6abefc6d45e8c0 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 9 Sep 2014 18:57:45 -0400 Subject: [PATCH 1/2] DiscIO: Simplify GetUniqueID in VolumeDirectory --- Source/Core/DiscIO/VolumeDirectory.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Source/Core/DiscIO/VolumeDirectory.cpp b/Source/Core/DiscIO/VolumeDirectory.cpp index 546401f31f..25441733cf 100644 --- a/Source/Core/DiscIO/VolumeDirectory.cpp +++ b/Source/Core/DiscIO/VolumeDirectory.cpp @@ -148,12 +148,8 @@ bool CVolumeDirectory::Read(u64 _Offset, u64 _Length, u8* _pBuffer) const std::string CVolumeDirectory::GetUniqueID() const { - char buffer[7]; - memcpy(buffer, m_diskHeader.data(), 6); - buffer[6] = 0; - - std::string id = buffer; - return id; + static const size_t ID_LENGTH = 6; + return std::string(m_diskHeader.begin(), m_diskHeader.begin() + ID_LENGTH); } void CVolumeDirectory::SetUniqueID(std::string _ID) From 9601f5ec5ff3346f837abbe4d3c5b5dc8b374b56 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 9 Sep 2014 19:01:20 -0400 Subject: [PATCH 2/2] DiscIO: Get rid of some casts and a c_str call in VolumeDirectory --- Source/Core/DiscIO/VolumeDirectory.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/Core/DiscIO/VolumeDirectory.cpp b/Source/Core/DiscIO/VolumeDirectory.cpp index 25441733cf..0111a21f97 100644 --- a/Source/Core/DiscIO/VolumeDirectory.cpp +++ b/Source/Core/DiscIO/VolumeDirectory.cpp @@ -152,13 +152,13 @@ std::string CVolumeDirectory::GetUniqueID() const return std::string(m_diskHeader.begin(), m_diskHeader.begin() + ID_LENGTH); } -void CVolumeDirectory::SetUniqueID(std::string _ID) +void CVolumeDirectory::SetUniqueID(std::string id) { - u32 length = (u32)_ID.length(); + size_t length = id.length(); if (length > 6) length = 6; - memcpy(m_diskHeader.data(), _ID.c_str(), length); + memcpy(m_diskHeader.data(), id.c_str(), length); } IVolume::ECountry CVolumeDirectory::GetCountry() const @@ -178,13 +178,13 @@ std::vector CVolumeDirectory::GetNames() const return std::vector(1, (char*)(&m_diskHeader[0x20])); } -void CVolumeDirectory::SetName(std::string _Name) +void CVolumeDirectory::SetName(std::string name) { - u32 length = (u32)_Name.length(); + size_t length = name.length(); if (length > MAX_NAME_LENGTH) length = MAX_NAME_LENGTH; - memcpy(&m_diskHeader[0x20], _Name.c_str(), length); + memcpy(&m_diskHeader[0x20], name.c_str(), length); m_diskHeader[length + 0x20] = 0; } @@ -260,7 +260,7 @@ bool CVolumeDirectory::SetApploader(const std::string& _rApploader) if (!_rApploader.empty()) { std::string data; - if (!File::ReadFileToString(_rApploader.c_str(), data)) + if (!File::ReadFileToString(_rApploader, data)) { PanicAlertT("Apploader unable to load from file"); return false;