summaryrefslogtreecommitdiff
path: root/Source/Core/DiscIO
diff options
context:
space:
mode:
authorShawn Hoffman <godisgovernment@gmail.com>2009-08-04 03:27:56 +0000
committerShawn Hoffman <godisgovernment@gmail.com>2009-08-04 03:27:56 +0000
commit62899da626b663e679ec7128f29c15161c968b2d (patch)
tree0f7e57db6278b13636c4c3ecc2ad36f92a4ac0ca /Source/Core/DiscIO
parent8b1aff8b5935f113e7551ac5e8395e270e40b78d (diff)
make CVolumeWAD::GetName() safer
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3938 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core/DiscIO')
-rw-r--r--Source/Core/DiscIO/Src/VolumeWad.cpp35
1 files changed, 13 insertions, 22 deletions
diff --git a/Source/Core/DiscIO/Src/VolumeWad.cpp b/Source/Core/DiscIO/Src/VolumeWad.cpp
index 32caec2cb0..bc4c658b35 100644
--- a/Source/Core/DiscIO/Src/VolumeWad.cpp
+++ b/Source/Core/DiscIO/Src/VolumeWad.cpp
@@ -113,34 +113,25 @@ std::string CVolumeWAD::GetName() const
return "Unknown";
// Offset to the english title
- char temp[85];
+ char temp[84];
if (!Read(0xF1 + OpeningBnrOffset, 84, (u8*)&temp) || Common::swap32(footer_size) < 0xF1)
return "Unknown";
- char out_temp[43];
- int j = 0;
-
- for (int i=0; i < 84; i++)
+ // Remove the null bytes due to 16bit char length
+ std::string out_temp;
+ for (int i = 0; i < sizeof(temp); i+=2)
{
- if (!(i & 1))
- {
- if (temp[i] != 0)
- out_temp[j] = temp[i];
- else
- {
- // Some wads have a few consecutive Null chars followed by text
- // as i don't know what to do there: replace the frst one with space
- if (out_temp[j-1] != 32)
- out_temp[j] = 32;
- else
- continue;
- }
-
- j++;
+ // Replace null chars with a single space per null section
+ if (temp[i] == '\0' && i > 0)
+ {
+ if (out_temp.at(out_temp.size()-1) != ' ')
+ out_temp.push_back(' ');
}
+ else
+ out_temp.push_back(temp[i]);
}
-
- out_temp[j] = 0;
+ // Make it a null terminated string
+ out_temp.replace(out_temp.end()-1, out_temp.end(), 1, '\0');
return out_temp;
}