1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-08-20 13:09:15 +00:00

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:
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

@@ -229,8 +229,8 @@ static void DumpGroup(IniLoadFile *ifile, const char * const group_name)
*/
static const char *FindItemValue(const char *name, IniGroup *grp, IniGroup *defaults)
{
IniItem *item = grp->GetItem(name, false);
if (item == nullptr && defaults != nullptr) item = defaults->GetItem(name, false);
IniItem *item = grp->GetItem(name);
if (item == nullptr && defaults != nullptr) item = defaults->GetItem(name);
if (item == nullptr || !item->value.has_value()) return nullptr;
return item->value->c_str();
}
@@ -321,14 +321,14 @@ static void DumpSections(IniLoadFile *ifile)
for (sgn = special_group_names; *sgn != nullptr; sgn++) if (grp->name == *sgn) break;
if (*sgn != nullptr) continue;
IniItem *template_item = templates_grp->GetItem(grp->name, false); // Find template value.
IniItem *template_item = templates_grp->GetItem(grp->name); // Find template value.
if (template_item == nullptr || !template_item->value.has_value()) {
FatalError("Cannot find template {}", grp->name);
}
DumpLine(template_item, grp, default_grp, _stored_output);
if (validation_grp != nullptr) {
IniItem *validation_item = validation_grp->GetItem(grp->name, false); // Find template value.
IniItem *validation_item = validation_grp->GetItem(grp->name); // Find template value.
if (validation_item != nullptr && validation_item->value.has_value()) {
DumpLine(validation_item, grp, default_grp, _post_amble_output);
}