From 33cc3a3dd9f3387e36778483122eb5391d1c9fc9 Mon Sep 17 00:00:00 2001 From: EmosewaMC <39972741+EmosewaMC@users.noreply.github.com> Date: Sun, 5 Jun 2022 20:58:51 -0700 Subject: [PATCH] Corrected string to long conversion For Windows, the definition for a long is 32 bits, not 64 bits like on other operating systems. This caused an issue on Windows only where a number larger than 32 bits was attempted to be converted to a long, the WorldServer would crash. This commit replaces all instances of `stol` with `stoull` to further define a long and reduce ambiguity of number length. --- dCommon/LDFFormat.cpp | 2 +- dDatabase/Tables/CDItemComponentTable.cpp | 2 +- dScripts/BaseFootRaceManager.cpp | 2 +- dScripts/NjMonastryBossInstance.cpp | 2 +- dScripts/SpawnPetBaseServer.cpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dCommon/LDFFormat.cpp b/dCommon/LDFFormat.cpp index 13fcb5cb..8290faec 100644 --- a/dCommon/LDFFormat.cpp +++ b/dCommon/LDFFormat.cpp @@ -54,7 +54,7 @@ LDFBaseData * LDFBaseData::DataFromString(const std::string& format) { } case LDF_TYPE_S32: { - int32_t data = static_cast(stol(dataArray[1])); + int32_t data = static_cast(stoull(dataArray[1])); return new LDFData(key, data); } diff --git a/dDatabase/Tables/CDItemComponentTable.cpp b/dDatabase/Tables/CDItemComponentTable.cpp index 149b2ce8..698f72a4 100644 --- a/dDatabase/Tables/CDItemComponentTable.cpp +++ b/dDatabase/Tables/CDItemComponentTable.cpp @@ -168,7 +168,7 @@ std::map CDItemComponentTable::ParseCraftingCurrencies(const CDIt // Checking for 2 here, not sure what to do when there's more stuff than expected if (amountSplit.size() == 2) { currencies.insert({ - std::stol(amountSplit[0]), + std::stoull(amountSplit[0]), std::stoi(amountSplit[1]) }); } diff --git a/dScripts/BaseFootRaceManager.cpp b/dScripts/BaseFootRaceManager.cpp index 0c5d9f19..0da51bc5 100644 --- a/dScripts/BaseFootRaceManager.cpp +++ b/dScripts/BaseFootRaceManager.cpp @@ -12,7 +12,7 @@ void BaseFootRaceManager::OnFireEventServerSide(Entity *self, Entity *sender, st if (splitArguments.size() > 1) { const auto eventName = splitArguments[0]; - const auto player = EntityManager::Instance()->GetEntity(std::stol(splitArguments[1])); + const auto player = EntityManager::Instance()->GetEntity(std::stoull(splitArguments[1])); if (player != nullptr) { if (eventName == "updatePlayer") { diff --git a/dScripts/NjMonastryBossInstance.cpp b/dScripts/NjMonastryBossInstance.cpp index 17c4b296..c6c8e324 100644 --- a/dScripts/NjMonastryBossInstance.cpp +++ b/dScripts/NjMonastryBossInstance.cpp @@ -99,7 +99,7 @@ void NjMonastryBossInstance::OnPlayerExit(Entity *self, Entity *player) { void NjMonastryBossInstance::OnActivityTimerDone(Entity *self, const std::string &name) { auto split = GeneralUtils::SplitString(name, TimerSplitChar); auto timerName = split[0]; - auto objectID = split.size() > 1 ? (LWOOBJID) std::stol(split[1]) : LWOOBJID_EMPTY; + auto objectID = split.size() > 1 ? (LWOOBJID) std::stoull(split[1]) : LWOOBJID_EMPTY; if (timerName == WaitingForPlayersTimer) { StartFight(self); diff --git a/dScripts/SpawnPetBaseServer.cpp b/dScripts/SpawnPetBaseServer.cpp index 4706da1d..d23e371a 100644 --- a/dScripts/SpawnPetBaseServer.cpp +++ b/dScripts/SpawnPetBaseServer.cpp @@ -55,7 +55,7 @@ bool SpawnPetBaseServer::CheckNumberOfPets(Entity *self, Entity* user) { if (petID.empty()) continue; - const auto* spawnedPet = EntityManager::Instance()->GetEntity(std::stol(petID)); + const auto* spawnedPet = EntityManager::Instance()->GetEntity(std::stoull(petID)); if (spawnedPet == nullptr) continue;