diff options
| author | JosJuice <josjuice@gmail.com> | 2017-11-02 21:05:37 +0100 |
|---|---|---|
| committer | JosJuice <josjuice@gmail.com> | 2017-11-03 23:17:40 +0100 |
| commit | 1dc2a85ccc2e3a23b9cd33d1503038223bfae320 (patch) | |
| tree | d25b91be57825f521e12c18c1abf4f0606427ea5 /Source/Core/DiscIO/Volume.cpp | |
| parent | 6902bbb696ea7089daded57569cca637a5e69eae (diff) | |
Avoid UB when reading Wii volume names
Diffstat (limited to 'Source/Core/DiscIO/Volume.cpp')
| -rw-r--r-- | Source/Core/DiscIO/Volume.cpp | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/Source/Core/DiscIO/Volume.cpp b/Source/Core/DiscIO/Volume.cpp index 9ae87466e2..e95a2b746f 100644 --- a/Source/Core/DiscIO/Volume.cpp +++ b/Source/Core/DiscIO/Volume.cpp @@ -26,17 +26,15 @@ namespace DiscIO const IOS::ES::TicketReader Volume::INVALID_TICKET{}; const IOS::ES::TMDReader Volume::INVALID_TMD{}; -std::map<Language, std::string> Volume::ReadWiiNames(const std::vector<u8>& data) +std::map<Language, std::string> Volume::ReadWiiNames(const std::vector<char16_t>& data) { std::map<Language, std::string> names; for (size_t i = 0; i < NUMBER_OF_LANGUAGES; ++i) { - size_t name_start = NAME_BYTES_LENGTH * i; - size_t name_end = name_start + NAME_BYTES_LENGTH; - if (data.size() >= name_end) + const size_t name_start = NAME_CHARS_LENGTH * i; + if (name_start + NAME_CHARS_LENGTH <= data.size()) { - std::string name = UTF16BEToUTF8(reinterpret_cast<const char16_t*>(data.data() + name_start), - NAME_STRING_LENGTH); + const std::string name = UTF16BEToUTF8(data.data() + name_start, NAME_CHARS_LENGTH); if (!name.empty()) names[static_cast<Language>(i)] = name; } |
