summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorLéo Lam <leo@innovatetechnologi.es>2017-10-28 22:40:05 +0200
committerLéo Lam <leo@innovatetechnologi.es>2017-10-28 22:40:05 +0200
commit7aa083388b96fcd1bc56c0746ab9559446516d71 (patch)
treee3a56614b16c6ef7a594c542d5c0c2a2ef306d9a /Source/Core
parent5d449c00e63e9e4dceeda1bca385b6831de12e0f (diff)
NANDImporter: Construct strings correctly
Use std::string(cstring, strnlen(cstring, max_length)) instead of trying to remove extra null characters manually, which is a bit ugly and error prone. And indeed, the original code contained a bug which would cause extra NULLs to not be removed at all if the string did not end with a NULL -- causing issues down the road when constructing paths for sub-entries.
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/DiscIO/NANDImporter.cpp5
-rw-r--r--Source/Core/DiscIO/NANDImporter.h2
2 files changed, 2 insertions, 5 deletions
diff --git a/Source/Core/DiscIO/NANDImporter.cpp b/Source/Core/DiscIO/NANDImporter.cpp
index 5a9983ce03..4256167b89 100644
--- a/Source/Core/DiscIO/NANDImporter.cpp
+++ b/Source/Core/DiscIO/NANDImporter.cpp
@@ -109,10 +109,7 @@ void NANDImporter::FindSuperblock()
std::string NANDImporter::GetPath(const NANDFSTEntry& entry, const std::string& parent_path)
{
- std::string name(reinterpret_cast<const char*>(&entry.name), sizeof(NANDFSTEntry::name));
- // Get rid of any extra null characters
- while (name.back() == '\0')
- name.pop_back();
+ std::string name(entry.name, strnlen(entry.name, sizeof(NANDFSTEntry::name)));
if (name.front() == '/' || parent_path.back() == '/')
return parent_path + name;
diff --git a/Source/Core/DiscIO/NANDImporter.h b/Source/Core/DiscIO/NANDImporter.h
index 09ed7034cb..185a8efd84 100644
--- a/Source/Core/DiscIO/NANDImporter.h
+++ b/Source/Core/DiscIO/NANDImporter.h
@@ -25,7 +25,7 @@ private:
#pragma pack(push, 1)
struct NANDFSTEntry
{
- u8 name[12];
+ char name[12];
u8 mode; // 0x0C
u8 attr; // 0x0D
u16 sub; // 0x0E