1
0
Fork 0

Lua API: Fixed md5 and sha1 hex formatting.

std::setw() is only valid for one output operation and needs to be set again in each loop repetition.
This commit is contained in:
Mattes D 2015-03-03 01:28:58 +01:00
parent 7767af9493
commit d4b505db02
1 changed files with 4 additions and 4 deletions

View File

@ -2392,10 +2392,10 @@ static int tolua_md5HexString(lua_State * tolua_S)
// Convert the md5 checksum to hex string:
std::stringstream Output;
Output << std::hex << std::setw(2) << std::setfill('0');
Output << std::hex << std::setfill('0');
for (size_t i = 0; i < ARRAYCOUNT(md5Output); i++)
{
Output << static_cast<unsigned short>(md5Output[i]); // Need to cast to a number, otherwise a char is output
Output << std::setw(2) << static_cast<unsigned short>(md5Output[i]); // Need to cast to a number, otherwise a char is output
}
lua_pushlstring(tolua_S, Output.str().c_str(), Output.str().size());
return 1;
@ -2438,10 +2438,10 @@ static int tolua_sha1HexString(lua_State * tolua_S)
// Convert the sha1 checksum to hex string:
std::stringstream Output;
Output << std::hex << std::setw(2) << std::setfill('0');
Output << std::hex << std::setfill('0');
for (size_t i = 0; i < ARRAYCOUNT(sha1Output); i++)
{
Output << static_cast<unsigned short>(sha1Output[i]); // Need to cast to a number, otherwise a char is output
Output << std::setw(2) << static_cast<unsigned short>(sha1Output[i]); // Need to cast to a number, otherwise a char is output
}
lua_pushlstring(tolua_S, Output.str().c_str(), Output.str().size());
return 1;