Skip to content

Commit

Permalink
Fix reading negative value for update fields from DB.
Browse files Browse the repository at this point in the history
Also generalize the use of 'strtoul' instead of 'atol' as we never need directly signed result.

fix cmangos/issues#773
  • Loading branch information
Cyberium committed Oct 12, 2015
1 parent 9db46a8 commit 9db455a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/game/Level3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2289,7 +2289,7 @@ bool ChatHandler::HandleLearnAllCommand(char* /*args*/)
int loop = 0;
while (strcmp(allSpellList[loop], "0"))
{
uint32 spell = atol((char*)allSpellList[loop++]);
uint32 spell = std::stoul((char*)allSpellList[loop++]);

if (m_session->GetPlayer()->HasSpell(spell))
continue;
Expand Down Expand Up @@ -2332,7 +2332,7 @@ bool ChatHandler::HandleLearnAllGMCommand(char* /*args*/)
uint16 gmSpellIter = 0;
while (strcmp(gmSpellList[gmSpellIter], "0"))
{
uint32 spell = atol((char*)gmSpellList[gmSpellIter++]);
uint32 spell = std::stoul((char*)gmSpellList[gmSpellIter++]);

SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo, m_session->GetPlayer()))
Expand Down
2 changes: 1 addition & 1 deletion src/game/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ bool Object::LoadValues(const char* data)
int index;
for (iter = tokens.begin(), index = 0; index < m_valuesCount; ++iter, ++index)
{
m_uint32Values[index] = atol((*iter).c_str());
m_uint32Values[index] = std::stoul((*iter).c_str());
}

return true;
Expand Down
6 changes: 3 additions & 3 deletions src/game/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void PlayerTaxi::LoadTaxiMask(const char* data)
(index < TaxiMaskSize) && (iter != tokens.end()); ++iter, ++index)
{
// load and set bits only for existing taxi nodes
m_taximask[index] = sTaxiNodesMask[index] & uint32(atol((*iter).c_str()));
m_taximask[index] = sTaxiNodesMask[index] & uint32(std::stoul((*iter).c_str()));
}
}

Expand All @@ -220,7 +220,7 @@ bool PlayerTaxi::LoadTaxiDestinationsFromString(const std::string& values, Team

for (Tokens::iterator iter = tokens.begin(); iter != tokens.end(); ++iter)
{
uint32 node = uint32(atol(iter->c_str()));
uint32 node = std::stoul(iter->c_str());
AddTaxiDestination(node);
}

Expand Down Expand Up @@ -14997,7 +14997,7 @@ void Player::_LoadIntoDataField(const char* data, uint32 startOffset, uint32 cou
uint32 index;
for (iter = tokens.begin(), index = 0; index < count; ++iter, ++index)
{
m_uint32Values[startOffset + index] = atol((*iter).c_str());
m_uint32Values[startOffset + index] = std::stoul((*iter).c_str());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/game/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9931,9 +9931,9 @@ void CharmInfo::LoadPetActionBar(const std::string& data)
for (iter = tokens.begin(), index = ACTION_BAR_INDEX_START; index < ACTION_BAR_INDEX_END; ++iter, ++index)
{
// use unsigned cast to avoid sign negative format use at long-> ActiveStates (int) conversion
uint8 type = (uint8)atol((*iter).c_str());
uint8 type = (uint8)std::stoul((*iter).c_str());
++iter;
uint32 action = atol((*iter).c_str());
uint32 action = std::stoul((*iter).c_str());

PetActionBar[index].SetActionAndType(action, ActiveStates(type));

Expand Down
2 changes: 1 addition & 1 deletion src/game/debugcmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ bool ChatHandler::HandleDebugGetLootRecipientCommand(char* /*args*/)

bool ChatHandler::HandleDebugSendQuestInvalidMsgCommand(char* args)
{
uint32 msg = atol(args);
uint32 msg = std::stoul(args);
m_session->GetPlayer()->SendCanTakeQuestResponse(msg);
return true;
}
Expand Down

0 comments on commit 9db455a

Please sign in to comment.