fix tiny buffer overflow in Hex2Ascii()

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2361 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard 2009-02-22 11:01:08 +00:00
parent e5cf9c8b8c
commit 8741026ba0
1 changed files with 5 additions and 2 deletions

View File

@ -76,7 +76,9 @@ u32 Ascii2Hex(std::string _Text)
u32 Result = 0;
// Max 32-bit values are supported
int Length = _Text.length(); if (Length > 4) Length = 4;
int Length = _Text.length();
if (Length > 4)
Length = 4;
for (int i = 0; i < Length; i++)
{
@ -86,11 +88,12 @@ u32 Ascii2Hex(std::string _Text)
// Return the value
return Result;
}
// Convert it back again
std::string Hex2Ascii(u32 _Text)
{
// Create temporary storate
char Result[4];
char Result[5]; // need space for the final \0
// Go through the four characters
sprintf(Result, "%c%c%c%c", _Text >> 24, _Text >> 16, _Text >> 8, _Text);
// Return the string