Codechange: Split GetItem with GetOrCreateItem. (#10952)

`IniGroup::GetItem()` returns nullptr if the item does not exist, but does not if the create parameter is set to true. Resolve CodeQL warnings with `GetOrCreateItem()` which returns a reference to the item instead.
This commit is contained in:
PeterN
2023-06-05 19:29:52 +01:00
committed by GitHub
parent 3b1407d240
commit 64d6ad50f9
8 changed files with 51 additions and 41 deletions

View File

@@ -278,7 +278,7 @@ void HotkeyList::Load(IniFile *ini)
{
IniGroup *group = ini->GetGroup(this->ini_group);
for (Hotkey &hotkey : this->items) {
IniItem *item = group->GetItem(hotkey.name, false);
IniItem *item = group->GetItem(hotkey.name);
if (item != nullptr) {
hotkey.keycodes.clear();
if (item->value.has_value()) ParseHotkeys(hotkey, item->value->c_str());
@@ -294,8 +294,8 @@ void HotkeyList::Save(IniFile *ini) const
{
IniGroup *group = ini->GetGroup(this->ini_group);
for (const Hotkey &hotkey : this->items) {
IniItem *item = group->GetItem(hotkey.name, true);
item->SetValue(SaveKeycodes(hotkey));
IniItem &item = group->GetOrCreateItem(hotkey.name);
item.SetValue(SaveKeycodes(hotkey));
}
}