Fix variants lowercasing causing stack smashing error.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-02-13 18:45:41 +01:00
parent 667821df28
commit a6f91faba4
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
1 changed files with 4 additions and 4 deletions

View File

@ -9,13 +9,13 @@ CreatureSpecies::CreatureSpecies(uint16_t id, std::string name, const SpeciesVar
bool CreatureSpecies::HasVariant(const std::string& name) const { bool CreatureSpecies::HasVariant(const std::string& name) const {
auto key = name; auto key = name;
std::transform(key.begin(), key.end(), key.end(), ::tolower); std::transform(key.begin(), key.end(), key.begin(), ::tolower);
return _variants.find(key) != _variants.end(); return _variants.find(key) != _variants.end();
} }
bool CreatureSpecies::TryGetVariant(const std::string& name, const SpeciesVariant*& out) const { bool CreatureSpecies::TryGetVariant(const std::string& name, const SpeciesVariant*& out) const {
auto key = name; auto key = name;
std::transform(key.begin(), key.end(), key.end(), ::tolower); std::transform(key.begin(), key.end(), key.begin(), ::tolower);
auto find = _variants.find(key); auto find = _variants.find(key);
if (find != _variants.end()) { if (find != _variants.end()) {
out = find->second; out = find->second;
@ -26,13 +26,13 @@ bool CreatureSpecies::TryGetVariant(const std::string& name, const SpeciesVarian
const SpeciesVariant* CreatureSpecies::GetVariant(const std::string& name) const { const SpeciesVariant* CreatureSpecies::GetVariant(const std::string& name) const {
auto key = name; auto key = name;
std::transform(key.begin(), key.end(), key.end(), ::tolower); std::transform(key.begin(), key.end(), key.begin(), ::tolower);
return _variants.at(key); return _variants.at(key);
} }
void CreatureSpecies::SetVariant(const std::string& name, const SpeciesVariant* variant) { void CreatureSpecies::SetVariant(const std::string& name, const SpeciesVariant* variant) {
auto key = name; auto key = name;
std::transform(key.begin(), key.end(), key.end(), ::tolower); std::transform(key.begin(), key.end(), key.begin(), ::tolower);
auto find = _variants.find(key); auto find = _variants.find(key);
if (find != _variants.end()) { if (find != _variants.end()) {
delete find->second; delete find->second;