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:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user