1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-20 02:42:42 +01:00

Codechange: explicitly initialise NewGRF-pool-object member variables

This commit is contained in:
Rubidium
2025-02-18 18:52:45 +01:00
committed by rubidium42
parent b64e8c0aea
commit 8b7c92dfe3
4 changed files with 61 additions and 60 deletions

View File

@@ -9,6 +9,7 @@
#include "stdafx.h"
#include <ranges>
#include "core/backup_type.hpp"
#include "core/container_func.hpp"
#include "debug.h"
@@ -5740,7 +5741,7 @@ static void NewSpriteGroup(ByteReader &buf)
group->again = buf.ReadByte();
} else if (type == 2) {
group->num_input = buf.ReadByte();
if (group->num_input > lengthof(group->subtract_input)) {
if (group->num_input > std::size(group->subtract_input)) {
GRFError *error = DisableGrf(STR_NEWGRF_ERROR_INDPROD_CALLBACK);
error->data = "too many inputs (max 16)";
return;
@@ -5753,7 +5754,7 @@ static void NewSpriteGroup(ByteReader &buf)
* as long as the result is not used. Mark it invalid so this
* can be tested later. */
group->version = 0xFF;
} else if (std::find(group->cargo_input, group->cargo_input + i, cargo) != group->cargo_input + i) {
} else if (auto v = group->cargo_input | std::views::take(i); std::ranges::find(v, cargo) != v.end()) {
GRFError *error = DisableGrf(STR_NEWGRF_ERROR_INDPROD_CALLBACK);
error->data = "duplicate input cargo";
return;
@@ -5762,7 +5763,7 @@ static void NewSpriteGroup(ByteReader &buf)
group->subtract_input[i] = buf.ReadByte();
}
group->num_output = buf.ReadByte();
if (group->num_output > lengthof(group->add_output)) {
if (group->num_output > std::size(group->add_output)) {
GRFError *error = DisableGrf(STR_NEWGRF_ERROR_INDPROD_CALLBACK);
error->data = "too many outputs (max 16)";
return;
@@ -5773,7 +5774,7 @@ static void NewSpriteGroup(ByteReader &buf)
if (!IsValidCargoType(cargo)) {
/* Mark this result as invalid to use */
group->version = 0xFF;
} else if (std::find(group->cargo_output, group->cargo_output + i, cargo) != group->cargo_output + i) {
} else if (auto v = group->cargo_output | std::views::take(i); std::ranges::find(v, cargo) != v.end()) {
GRFError *error = DisableGrf(STR_NEWGRF_ERROR_INDPROD_CALLBACK);
error->data = "duplicate output cargo";
return;