Skip to content

Commit

Permalink
fix: player wheel string conversion (#2967)
Browse files Browse the repository at this point in the history
Now checks to ensure that strings are numeric before converting them to
numbers with std::stoull. If the strings are not numeric, it falls back
to a lexicographical comparison, preventing crashes caused by invalid
conversions.

Resolves #2966
  • Loading branch information
kaleohanopahala authored Oct 11, 2024
1 parent 35550d1 commit 34baa0a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/creatures/players/wheel/player_wheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,12 +771,18 @@ std::vector<PlayerWheelGem> PlayerWheel::getRevealedGems() const {
if (unlockedGemUUIDs.empty()) {
return unlockedGems;
}

std::vector<std::string> sortedUnlockedGemGUIDs;
for (const auto &uuid : unlockedGemUUIDs) {
sortedUnlockedGemGUIDs.push_back(uuid);
}

std::sort(sortedUnlockedGemGUIDs.begin(), sortedUnlockedGemGUIDs.end(), [](const std::string &a, const std::string &b) {
return std::stoull(a) < std::stoull(b);
if (std::ranges::all_of(a, ::isdigit) && std::ranges::all_of(b, ::isdigit)) {
return std::stoull(a) < std::stoull(b);
} else {
return a < b;
}
});

for (const auto &uuid : sortedUnlockedGemGUIDs) {
Expand Down

0 comments on commit 34baa0a

Please sign in to comment.