make CVolumeWAD::GetName() safer
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3938 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
8b1aff8b59
commit
62899da626
|
@ -113,34 +113,25 @@ std::string CVolumeWAD::GetName() const
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
|
|
||||||
// Offset to the english title
|
// Offset to the english title
|
||||||
char temp[85];
|
char temp[84];
|
||||||
if (!Read(0xF1 + OpeningBnrOffset, 84, (u8*)&temp) || Common::swap32(footer_size) < 0xF1)
|
if (!Read(0xF1 + OpeningBnrOffset, 84, (u8*)&temp) || Common::swap32(footer_size) < 0xF1)
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
|
|
||||||
char out_temp[43];
|
// Remove the null bytes due to 16bit char length
|
||||||
int j = 0;
|
std::string out_temp;
|
||||||
|
for (int i = 0; i < sizeof(temp); i+=2)
|
||||||
for (int i=0; i < 84; i++)
|
|
||||||
{
|
{
|
||||||
if (!(i & 1))
|
// Replace null chars with a single space per null section
|
||||||
|
if (temp[i] == '\0' && i > 0)
|
||||||
{
|
{
|
||||||
if (temp[i] != 0)
|
if (out_temp.at(out_temp.size()-1) != ' ')
|
||||||
out_temp[j] = temp[i];
|
out_temp.push_back(' ');
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
out_temp.push_back(temp[i]);
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
// Make it a null terminated string
|
||||||
j++;
|
out_temp.replace(out_temp.end()-1, out_temp.end(), 1, '\0');
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
out_temp[j] = 0;
|
|
||||||
|
|
||||||
return out_temp;
|
return out_temp;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue