Use strn0cpy instead of strcpy when copying consent name buffers

Add nullptr checks to consent functions that accept char pointers
This commit is contained in:
hg
2020-01-30 20:00:01 -05:00
parent 9689787e56
commit 14c070f845
3 changed files with 22 additions and 15 deletions
+13 -9
View File
@@ -662,21 +662,25 @@ void Corpse::DepopPlayerCorpse() {
void Corpse::AddConsentName(const char* add_name)
{
for (const auto& n : consent_names) {
if (strcasecmp(n.c_str(), add_name) == 0) {
return;
if (add_name) {
for (const auto& n : consent_names) {
if (strcasecmp(n.c_str(), add_name) == 0) {
return;
}
}
consent_names.emplace_back(add_name);
}
consent_names.emplace_back(add_name);
}
void Corpse::RemoveConsentName(const char* rem_name)
{
consent_names.erase(std::remove_if(consent_names.begin(), consent_names.end(),
[rem_name](const std::string& n) {
return strcasecmp(n.c_str(), rem_name) == 0;
}
), consent_names.end());
if (rem_name) {
consent_names.erase(std::remove_if(consent_names.begin(), consent_names.end(),
[rem_name](const std::string& n) {
return strcasecmp(n.c_str(), rem_name) == 0;
}
), consent_names.end());
}
}
uint32 Corpse::CountItems() {