aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNayd <dnpd.dd@gmail.com>2014-11-26 02:21:50 +0000
committerNayd <dnpd.dd@gmail.com>2014-11-26 02:21:50 +0000
commit24c173f387044496d581255545ed94c988f3ae3b (patch)
tree1bb4a1518fc3971f707f02a439ed25fb875eb7e8 /src
parentc73474305320c926c7d81cd8ae576d5c3a72f1c9 (diff)
Core: Use the correct function to convert strings to unsigned longs and unsigned long longs
Fixes wrong data being inserted into the database (i.e explored zones). More info in #13493 Fixes #13493 Thanks to @jackpoz for finding the code issue and @Vavehl for an expectional bug report. Conflicts: src/server/game/Entities/Player/Player.cpp src/server/game/Globals/ObjectMgr.cpp src/server/scripts/Commands/cs_misc.cpp src/server/scripts/Commands/cs_modify.cpp
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Chat/Chat.cpp13
-rw-r--r--src/server/game/Entities/Object/Object.cpp2
-rw-r--r--src/server/game/Entities/Player/Player.cpp4
-rw-r--r--src/server/game/Entities/Unit/Unit.cpp2
-rw-r--r--src/server/game/Globals/ObjectMgr.cpp16
-rw-r--r--src/server/game/Handlers/CharacterHandler.cpp2
-rw-r--r--src/server/game/Tools/PlayerDump.cpp8
-rw-r--r--src/server/scripts/Commands/cs_debug.cpp4
-rw-r--r--src/server/scripts/Commands/cs_gobject.cpp4
-rw-r--r--src/server/scripts/Commands/cs_group.cpp2
-rw-r--r--src/server/scripts/Commands/cs_list.cpp16
-rw-r--r--src/server/scripts/Commands/cs_misc.cpp12
-rw-r--r--src/server/scripts/Commands/cs_npc.cpp10
-rw-r--r--src/server/scripts/Commands/cs_quest.cpp8
-rw-r--r--src/server/shared/Common.h3
15 files changed, 53 insertions, 53 deletions
diff --git a/src/server/game/Chat/Chat.cpp b/src/server/game/Chat/Chat.cpp
index 6f614994489..f05ce5bded9 100644
--- a/src/server/game/Chat/Chat.cpp
+++ b/src/server/game/Chat/Chat.cpp
@@ -982,7 +982,7 @@ uint32 ChatHandler::extractSpellIdFromLink(char* text)
if (!idS)
return 0;
- uint32 id = (uint32)atol(idS);
+ uint32 id = atoul(idS);
switch (type)
{
@@ -995,13 +995,10 @@ uint32 ChatHandler::extractSpellIdFromLink(char* text)
if (!talentEntry)
return 0;
- int32 rank = param1_str ? (uint32)atol(param1_str) : 0;
+ uint32 rank = param1_str ? atol(param1_str) : 0u;
if (rank >= MAX_TALENT_RANK)
return 0;
- if (rank < 0)
- rank = 0;
-
return talentEntry->RankID[rank];
}
case SPELL_LINK_ENCHANT:
@@ -1009,7 +1006,7 @@ uint32 ChatHandler::extractSpellIdFromLink(char* text)
return id;
case SPELL_LINK_GLYPH:
{
- uint32 glyph_prop_id = param1_str ? (uint32)atol(param1_str) : 0;
+ uint32 glyph_prop_id = param1_str ? atoul(param1_str) : 0;
GlyphPropertiesEntry const* glyphPropEntry = sGlyphPropertiesStore.LookupEntry(glyph_prop_id);
if (!glyphPropEntry)
@@ -1082,7 +1079,7 @@ ObjectGuid ChatHandler::extractGuidFromLink(char* text)
}
case SPELL_LINK_CREATURE:
{
- uint32 lowguid = (uint32)atol(idS);
+ uint32 lowguid = atoul(idS);
if (CreatureData const* data = sObjectMgr->GetCreatureData(lowguid))
return ObjectGuid(HIGHGUID_UNIT, data->id, lowguid);
@@ -1091,7 +1088,7 @@ ObjectGuid ChatHandler::extractGuidFromLink(char* text)
}
case SPELL_LINK_GAMEOBJECT:
{
- uint32 lowguid = (uint32)atol(idS);
+ uint32 lowguid = atoul(idS);
if (GameObjectData const* data = sObjectMgr->GetGOData(lowguid))
return ObjectGuid(HIGHGUID_GAMEOBJECT, data->id, lowguid);
diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp
index 4ffddde021c..6702815870f 100644
--- a/src/server/game/Entities/Object/Object.cpp
+++ b/src/server/game/Entities/Object/Object.cpp
@@ -607,7 +607,7 @@ void Object::_LoadIntoDataField(std::string const& data, uint32 startOffset, uin
for (uint32 index = 0; index < count; ++index)
{
- m_uint32Values[startOffset + index] = atol(tokens[index]);
+ m_uint32Values[startOffset + index] = atoul(tokens[index]);
_changesMask.SetBit(startOffset + index);
}
}
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index 048b2f8e9bb..04e6cb000f8 100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -203,7 +203,7 @@ void PlayerTaxi::LoadTaxiMask(std::string const &data)
for (Tokenizer::const_iterator iter = tokens.begin(); index < TaxiMaskSize && iter != tokens.end(); ++iter, ++index)
{
// load and set bits only for existing taxi nodes
- m_taximask[index] = sTaxiNodesMask[index] & uint32(atol(*iter));
+ m_taximask[index] = sTaxiNodesMask[index] & atoul(*iter);
}
}
@@ -229,7 +229,7 @@ bool PlayerTaxi::LoadTaxiDestinationsFromString(const std::string& values, uint3
for (Tokenizer::const_iterator iter = Tokenizer.begin(); iter != Tokenizer.end(); ++iter)
{
- uint32 node = uint32(atol(*iter));
+ uint32 node = atoul(*iter);
AddTaxiDestination(node);
}
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp
index 9a4b7a347c8..beac32b0145 100644
--- a/src/server/game/Entities/Unit/Unit.cpp
+++ b/src/server/game/Entities/Unit/Unit.cpp
@@ -13852,7 +13852,7 @@ void CharmInfo::LoadPetActionBar(const std::string& data)
// use unsigned cast to avoid sign negative format use at long-> ActiveStates (int) conversion
ActiveStates type = ActiveStates(atol(*iter));
++iter;
- uint32 action = uint32(atol(*iter));
+ uint32 action = atoul(*iter);
PetActionBar[index].SetActionAndType(action, type);
diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp
index 9e31e901189..0d6bdadb875 100644
--- a/src/server/game/Globals/ObjectMgr.cpp
+++ b/src/server/game/Globals/ObjectMgr.cpp
@@ -556,17 +556,17 @@ void ObjectMgr::LoadCreatureTemplateAddons()
creatureAddon.auras.resize(tokens.size());
for (Tokenizer::const_iterator itr = tokens.begin(); itr != tokens.end(); ++itr)
{
- SpellInfo const* AdditionalSpellInfo = sSpellMgr->GetSpellInfo(uint32(atol(*itr)));
+ SpellInfo const* AdditionalSpellInfo = sSpellMgr->GetSpellInfo(atoul(*itr));
if (!AdditionalSpellInfo)
{
- TC_LOG_ERROR("sql.sql", "Creature (Entry: %u) has wrong spell %u defined in `auras` field in `creature_template_addon`.", entry, uint32(atol(*itr)));
+ TC_LOG_ERROR("sql.sql", "Creature (Entry: %u) has wrong spell %u defined in `auras` field in `creature_template_addon`.", entry, atoul(*itr));
continue;
}
if (AdditionalSpellInfo->HasAura(SPELL_AURA_CONTROL_VEHICLE))
- TC_LOG_ERROR("sql.sql", "Creature (Entry: %u) has SPELL_AURA_CONTROL_VEHICLE aura %u defined in `auras` field in `creature_template_addon`.", entry, uint32(atol(*itr)));
+ TC_LOG_ERROR("sql.sql", "Creature (Entry: %u) has SPELL_AURA_CONTROL_VEHICLE aura %u defined in `auras` field in `creature_template_addon`.", entry, atoul(*itr));
- creatureAddon.auras[i++] = uint32(atol(*itr));
+ creatureAddon.auras[i++] = atoul(*itr);
}
if (creatureAddon.mount)
@@ -1004,17 +1004,17 @@ void ObjectMgr::LoadCreatureAddons()
creatureAddon.auras.resize(tokens.size());
for (Tokenizer::const_iterator itr = tokens.begin(); itr != tokens.end(); ++itr)
{
- SpellInfo const* AdditionalSpellInfo = sSpellMgr->GetSpellInfo(uint32(atol(*itr)));
+ SpellInfo const* AdditionalSpellInfo = sSpellMgr->GetSpellInfo(atoul(*itr));
if (!AdditionalSpellInfo)
{
- TC_LOG_ERROR("sql.sql", "Creature (GUID: %u) has wrong spell %u defined in `auras` field in `creature_addon`.", guid, uint32(atol(*itr)));
+ TC_LOG_ERROR("sql.sql", "Creature (GUID: %u) has wrong spell %u defined in `auras` field in `creature_addon`.", guid, atoul(*itr));
continue;
}
if (AdditionalSpellInfo->HasAura(SPELL_AURA_CONTROL_VEHICLE))
- TC_LOG_ERROR("sql.sql", "Creature (GUID: %u) has SPELL_AURA_CONTROL_VEHICLE aura %u defined in `auras` field in `creature_addon`.", guid, uint32(atol(*itr)));
+ TC_LOG_ERROR("sql.sql", "Creature (GUID: %u) has SPELL_AURA_CONTROL_VEHICLE aura %u defined in `auras` field in `creature_addon`.", guid, atoul(*itr));
- creatureAddon.auras[i++] = uint32(atol(*itr));
+ creatureAddon.auras[i++] = atoul(*itr);
}
if (creatureAddon.mount)
diff --git a/src/server/game/Handlers/CharacterHandler.cpp b/src/server/game/Handlers/CharacterHandler.cpp
index 18cd5d5bd06..7e218b601e0 100644
--- a/src/server/game/Handlers/CharacterHandler.cpp
+++ b/src/server/game/Handlers/CharacterHandler.cpp
@@ -2004,7 +2004,7 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recvData)
}
for (uint32 index = 0; index < ktcount; ++index)
- knownTitles[index] = atol(tokens[index]);
+ knownTitles[index] = atoul(tokens[index]);
for (std::map<uint32, uint32>::const_iterator it = sObjectMgr->FactionChangeTitles.begin(); it != sObjectMgr->FactionChangeTitles.end(); ++it)
{
diff --git a/src/server/game/Tools/PlayerDump.cpp b/src/server/game/Tools/PlayerDump.cpp
index 584331ad393..136f8aab22c 100644
--- a/src/server/game/Tools/PlayerDump.cpp
+++ b/src/server/game/Tools/PlayerDump.cpp
@@ -527,10 +527,10 @@ DumpReturn PlayerDumpReader::LoadDump(std::string const& file, uint32 account, s
if (!changenth(line, 2, chraccount)) // characters.account update
ROLLBACK(DUMP_FILE_BROKEN);
- race = uint8(atol(getnth(line, 4).c_str()));
- playerClass = uint8(atol(getnth(line, 5).c_str()));
- gender = uint8(atol(getnth(line, 6).c_str()));
- level = uint8(atol(getnth(line, 7).c_str()));
+ race = uint8(atoul(getnth(line, 4).c_str()));
+ playerClass = uint8(atoul(getnth(line, 5).c_str()));
+ gender = uint8(atoul(getnth(line, 6).c_str()));
+ level = uint8(atoul(getnth(line, 7).c_str()));
if (name.empty())
{
// check if the original name already exists
diff --git a/src/server/scripts/Commands/cs_debug.cpp b/src/server/scripts/Commands/cs_debug.cpp
index d3d012e70d5..2eebc9cae10 100644
--- a/src/server/scripts/Commands/cs_debug.cpp
+++ b/src/server/scripts/Commands/cs_debug.cpp
@@ -488,7 +488,7 @@ public:
static bool HandleDebugSendQuestPartyMsgCommand(ChatHandler* handler, char const* args)
{
- uint32 msg = atol((char*)args);
+ uint32 msg = atoul(args);
handler->GetSession()->GetPlayer()->SendPushToPartyResponse(handler->GetSession()->GetPlayer(), msg);
return true;
}
@@ -507,7 +507,7 @@ public:
static bool HandleDebugSendQuestInvalidMsgCommand(ChatHandler* handler, char const* args)
{
- QuestFailedReason msg = static_cast<QuestFailedReason>(atol((char*)args));
+ QuestFailedReason msg = static_cast<QuestFailedReason>(atoul(args));
handler->GetSession()->GetPlayer()->SendCanTakeQuestResponse(msg);
return true;
}
diff --git a/src/server/scripts/Commands/cs_gobject.cpp b/src/server/scripts/Commands/cs_gobject.cpp
index f3ddc6f0137..c0bf2a6bb84 100644
--- a/src/server/scripts/Commands/cs_gobject.cpp
+++ b/src/server/scripts/Commands/cs_gobject.cpp
@@ -118,7 +118,7 @@ public:
if (!id)
return false;
- uint32 objectId = atol(id);
+ uint32 objectId = atoul(id);
if (!objectId)
return false;
@@ -238,7 +238,7 @@ public:
if (!id)
return false;
- uint32 objectId = atol(id);
+ uint32 objectId = atoul(id);
if (objectId)
result = WorldDatabase.PQuery("SELECT guid, id, position_x, position_y, position_z, orientation, map, phaseMask, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM gameobject WHERE map = '%i' AND id = '%u' ORDER BY order_ ASC LIMIT 1",
diff --git a/src/server/scripts/Commands/cs_group.cpp b/src/server/scripts/Commands/cs_group.cpp
index a558d977b85..08ed8077686 100644
--- a/src/server/scripts/Commands/cs_group.cpp
+++ b/src/server/scripts/Commands/cs_group.cpp
@@ -269,7 +269,7 @@ public:
const char* onlineState = "";
// Parse the guid to uint32...
- ObjectGuid parseGUID(HIGHGUID_PLAYER, uint32(atol((char*)args)));
+ ObjectGuid parseGUID(HIGHGUID_PLAYER, atoul(args));
// ... and try to extract a player out of it.
if (sObjectMgr->GetPlayerNameByGUID(parseGUID, nameTarget))
diff --git a/src/server/scripts/Commands/cs_list.cpp b/src/server/scripts/Commands/cs_list.cpp
index 0f21200c22d..80b1336985e 100644
--- a/src/server/scripts/Commands/cs_list.cpp
+++ b/src/server/scripts/Commands/cs_list.cpp
@@ -65,7 +65,7 @@ public:
if (!id)
return false;
- uint32 creatureId = atol(id);
+ uint32 creatureId = atoul(id);
if (!creatureId)
{
handler->PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, creatureId);
@@ -82,7 +82,7 @@ public:
}
char* countStr = strtok(NULL, " ");
- uint32 count = countStr ? atol(countStr) : 10;
+ uint32 count = countStr ? atoul(countStr) : 10;
if (count == 0)
return false;
@@ -133,11 +133,11 @@ public:
if (!*args)
return false;
- char* id = handler->extractKeyFromLink((char*)args, "Hitem");
+ char const* id = handler->extractKeyFromLink((char*)args, "Hitem");
if (!id)
return false;
- uint32 itemId = atol(id);
+ uint32 itemId = atoul(id);
if (!itemId)
{
handler->PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
@@ -154,7 +154,7 @@ public:
}
char* countStr = strtok(NULL, " ");
- uint32 count = countStr ? atol(countStr) : 10;
+ uint32 count = countStr ? atoul(countStr) : 10;
if (count == 0)
return false;
@@ -354,7 +354,7 @@ public:
if (!id)
return false;
- uint32 gameObjectId = atol(id);
+ uint32 gameObjectId = atoul(id);
if (!gameObjectId)
{
handler->PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, gameObjectId);
@@ -371,7 +371,7 @@ public:
}
char* countStr = strtok(NULL, " ");
- uint32 count = countStr ? atol(countStr) : 10;
+ uint32 count = countStr ? atoul(countStr) : 10;
if (count == 0)
return false;
@@ -476,7 +476,7 @@ public:
if (!*args)
return false;
- ObjectGuid parseGUID(HIGHGUID_PLAYER, uint32(atol((char*)args)));
+ ObjectGuid parseGUID(HIGHGUID_PLAYER, atoul(args));
if (sObjectMgr->GetPlayerNameByGUID(parseGUID, targetName))
{
diff --git a/src/server/scripts/Commands/cs_misc.cpp b/src/server/scripts/Commands/cs_misc.cpp
index a853a02bb11..884596f5974 100644
--- a/src/server/scripts/Commands/cs_misc.cpp
+++ b/src/server/scripts/Commands/cs_misc.cpp
@@ -1134,7 +1134,7 @@ public:
char const* id = handler->extractKeyFromLink((char*)args, "Hitem");
if (!id)
return false;
- itemId = uint32(atol(id));
+ itemId = atoul(id);
}
char const* ccount = strtok(NULL, " ");
@@ -1216,7 +1216,7 @@ public:
if (!id)
return false;
- uint32 itemSetId = atol(id);
+ uint32 itemSetId = atoul(id);
// prevent generation all items with itemset field value '0'
if (itemSetId == 0)
@@ -1357,7 +1357,7 @@ public:
return false;
}
- int32 level = uint32(atol(levelStr));
+ int32 level = atol(levelStr);
Player* target = handler->getSelectedPlayer();
if (!target)
@@ -1379,7 +1379,7 @@ public:
// If our target does not yet have the skill they are trying to add to them, the chosen level also becomes
// the max level of the new profession.
- uint16 max = maxPureSkill ? atol (maxPureSkill) : targetHasSkill ? target->GetPureMaxSkillValue(skill) : uint16(level);
+ uint16 max = maxPureSkill ? atoul(maxPureSkill) : targetHasSkill ? target->GetPureMaxSkillValue(skill) : uint16(level);
if (level <= 0 || level > max || max <= 0)
return false;
@@ -1419,7 +1419,7 @@ public:
PreparedStatement* stmt = NULL;
// To make sure we get a target, we convert our guid to an omniversal...
- ObjectGuid parseGUID(HIGHGUID_PLAYER, uint32(atol((char*)args)));
+ ObjectGuid parseGUID(HIGHGUID_PLAYER, atoul(args));
// ... and make sure we get a target, somehow.
if (sObjectMgr->GetPlayerNameByGUID(parseGUID, targetName))
@@ -1780,7 +1780,7 @@ public:
uint32 totalmail = uint32(fields[1].GetUInt64());
// ... we have to convert it from Char to int. We can use totalmail as it is
- rmailint = atol(readmail.c_str());
+ rmailint = atoul(readmail.c_str());
// Output XXI. LANG_INFO_CHR_MAILS if at least one mail is given
if (totalmail >= 1)
diff --git a/src/server/scripts/Commands/cs_npc.cpp b/src/server/scripts/Commands/cs_npc.cpp
index 987c12debb7..719dcefacd2 100644
--- a/src/server/scripts/Commands/cs_npc.cpp
+++ b/src/server/scripts/Commands/cs_npc.cpp
@@ -326,15 +326,15 @@ public:
char* fmaxcount = strtok(NULL, " "); //add maxcount, default: 0
uint32 maxcount = 0;
if (fmaxcount)
- maxcount = atol(fmaxcount);
+ maxcount = atoul(fmaxcount);
char* fincrtime = strtok(NULL, " "); //add incrtime, default: 0
uint32 incrtime = 0;
if (fincrtime)
- incrtime = atol(fincrtime);
+ incrtime = atoul(fincrtime);
char* fextendedcost = strtok(NULL, " "); //add ExtendedCost, default: 0
- uint32 extendedcost = fextendedcost ? atol(fextendedcost) : 0;
+ uint32 extendedcost = fextendedcost ? atoul(fextendedcost) : 0;
Creature* vendor = handler->getSelectedCreature();
if (!vendor)
{
@@ -564,7 +564,7 @@ public:
handler->SetSentErrorMessage(true);
return false;
}
- uint32 itemId = atol(pitem);
+ uint32 itemId = atoul(pitem);
if (!sObjectMgr->RemoveVendorItem(vendor->GetEntry(), itemId))
{
@@ -1321,7 +1321,7 @@ public:
return false;
}
- ObjectGuid receiver_guid(HIGHGUID_PLAYER, uint32(atol(receiver_str)));
+ ObjectGuid receiver_guid(HIGHGUID_PLAYER, atoul(receiver_str));
// check online security
Player* receiver = ObjectAccessor::FindPlayer(receiver_guid);
diff --git a/src/server/scripts/Commands/cs_quest.cpp b/src/server/scripts/Commands/cs_quest.cpp
index fb486128049..9f7098b9134 100644
--- a/src/server/scripts/Commands/cs_quest.cpp
+++ b/src/server/scripts/Commands/cs_quest.cpp
@@ -67,7 +67,7 @@ public:
if (!cId)
return false;
- uint32 entry = atol(cId);
+ uint32 entry = atoul(cId);
Quest const* quest = sObjectMgr->GetQuestTemplate(entry);
@@ -112,7 +112,7 @@ public:
if (!cId)
return false;
- uint32 entry = atol(cId);
+ uint32 entry = atoul(cId);
Quest const* quest = sObjectMgr->GetQuestTemplate(entry);
@@ -165,7 +165,7 @@ public:
if (!cId)
return false;
- uint32 entry = atol(cId);
+ uint32 entry = atoul(cId);
Quest const* quest = sObjectMgr->GetQuestTemplate(entry);
@@ -269,7 +269,7 @@ public:
if (!cId)
return false;
- uint32 entry = atol(cId);
+ uint32 entry = atoul(cId);
Quest const* quest = sObjectMgr->GetQuestTemplate(entry);
diff --git a/src/server/shared/Common.h b/src/server/shared/Common.h
index 27e6cb63514..8ffb138379a 100644
--- a/src/server/shared/Common.h
+++ b/src/server/shared/Common.h
@@ -79,6 +79,9 @@
inline float finiteAlways(float f) { return std::isfinite(f) ? f : 0.0f; }
+inline unsigned long atoul(char const* str) { return strtoul(str, nullptr, 10); }
+inline unsigned long long atoull(char const* str) { return strtoull(str, nullptr, 10); }
+
#define STRINGIZE(a) #a
enum TimeConstants