diff options
| author | Shawn Hoffman <godisgovernment@gmail.com> | 2011-11-27 23:17:10 -0800 |
|---|---|---|
| committer | Shawn Hoffman <godisgovernment@gmail.com> | 2012-01-17 23:59:48 -0800 |
| commit | bef3d7229eca9a7f9568abf72de6b4d467feee9f (patch) | |
| tree | f9ef501588cc7d14cd20a90f5a16ac4ce716cf49 /Source/Core/DiscIO/Src/BannerLoaderWii.cpp | |
| parent | 79ca43226cfa5363bf6826d14c9518c7b26f6078 (diff) | |
Ensure comment strings in CBannerLoaderWii::SWiiBanner are null-terminated. Fixes issue 5012.
Signed-off-by: Shawn Hoffman <godisgovernment@gmail.com>
Diffstat (limited to 'Source/Core/DiscIO/Src/BannerLoaderWii.cpp')
| -rw-r--r-- | Source/Core/DiscIO/Src/BannerLoaderWii.cpp | 85 |
1 files changed, 36 insertions, 49 deletions
diff --git a/Source/Core/DiscIO/Src/BannerLoaderWii.cpp b/Source/Core/DiscIO/Src/BannerLoaderWii.cpp index ab66a346d4..b23dc4d91a 100644 --- a/Source/Core/DiscIO/Src/BannerLoaderWii.cpp +++ b/Source/Core/DiscIO/Src/BannerLoaderWii.cpp @@ -144,45 +144,59 @@ bool CBannerLoaderWii::GetBanner(u32* _pBannerImage) return true; } -bool CBannerLoaderWii::GetName(std::string* _rName) +bool CBannerLoaderWii::GetStringFromComments(const CommentIndex index, std::string& s) { + bool ret = false; + if (IsValid()) { // find Banner type - SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile; + SWiiBanner *pBanner = (SWiiBanner*)m_pBannerFile; - std::string name; - if (CopyBeUnicodeToString(name, pBanner->m_Comment[0], WII_BANNER_COMMENT_SIZE)) - { - for (int i = 0; i < 6; i++) - { - _rName[i] = name; - } - return true; - } + // Ensure the string is null-terminating, since the banner format + // doesn't require it + u16 *src = new u16[COMMENT_SIZE + 1]; + memcpy(src, &pBanner->m_Comment[index], COMMENT_SIZE * sizeof(u16)); + src[COMMENT_SIZE] = 0; + + ret = CopyBeUnicodeToString(s, src, COMMENT_SIZE + 1); + + delete [] src; } - return false; + + return ret; } -bool CBannerLoaderWii::GetName(std::vector<std::wstring>& _rNames) +bool CBannerLoaderWii::GetStringFromComments(const CommentIndex index, std::wstring& s) { if (IsValid()) { // find Banner type SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile; - std::wstring temp; - for (int i = 0; i < WII_BANNER_COMMENT_SIZE; ++i) - { - temp.push_back(Common::swap16(pBanner->m_Comment[0][i])); - } - _rNames.push_back(temp); + std::wstring description; + for (int i = 0; i < COMMENT_SIZE; ++i) + description.push_back(Common::swap16(pBanner->m_Comment[index][i])); + + s = description; return true; } - return false; } +bool CBannerLoaderWii::GetName(std::string* _rName) +{ + return GetStringFromComments(NAME_IDX, *_rName); +} + +bool CBannerLoaderWii::GetName(std::vector<std::wstring>& _rNames) +{ + std::wstring temp; + bool ret = GetStringFromComments(NAME_IDX, temp); + _rNames.push_back(temp); + return ret; +} + bool CBannerLoaderWii::GetCompany(std::string& _rCompany) { _rCompany = "N/A"; @@ -191,39 +205,12 @@ bool CBannerLoaderWii::GetCompany(std::string& _rCompany) bool CBannerLoaderWii::GetDescription(std::string* _rDescription) { - if (IsValid()) - { - // find Banner type - SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile; - - std::string description; - if (CopyBeUnicodeToString(description, pBanner->m_Comment[1], WII_BANNER_COMMENT_SIZE)) - { - for (int i = 0; i< 6; i++) - { - _rDescription[i] = description; - } - return true; - } - } - return false; + return GetStringFromComments(DESC_IDX, *_rDescription); } bool CBannerLoaderWii::GetDescription(std::wstring& _rDescription) { - if (IsValid()) - { - // find Banner type - SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile; - - std::wstring description; - for (int i = 0; i < WII_BANNER_COMMENT_SIZE; ++i) - description.push_back(Common::swap16(pBanner->m_Comment[1][i])); - - _rDescription = description; - return true; - } - return false; + return GetStringFromComments(DESC_IDX, _rDescription); } void CBannerLoaderWii::decode5A3image(u32* dst, u16* src, int width, int height) |
