summaryrefslogtreecommitdiff
path: root/src/newgrf.cpp
diff options
context:
space:
mode:
authorYexo <yexo@openttd.org>2020-06-01 11:25:58 +0200
committerYexo <t.marinussen@gmail.com>2020-06-01 12:44:02 +0200
commitf827bc8c1ae83ea4f71347da9c8cb0468f386452 (patch)
tree6a2a90ef3da9e5b20063e175cfb6adbcc13741d6 /src/newgrf.cpp
parenta9b3312d1a4962d07a2e7976e8352c7113201a9e (diff)
downloadopenttd-f827bc8c1ae83ea4f71347da9c8cb0468f386452.tar.xz
Fix #8166: don't crash on loading an invalid roadtype newgrf
Initialization code for GRFFile::roadtype_map was copied from railtype_map. But while RailType is a byte-sized enum and could thus be initialized via memset, RoadType doesn't have a defined size.
Diffstat (limited to 'src/newgrf.cpp')
-rw-r--r--src/newgrf.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 6b5a2f9ce..6f12fbbf9 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -8718,18 +8718,18 @@ GRFFile::GRFFile(const GRFConfig *config)
}
/* Initialise rail type map with default rail types */
- memset(this->railtype_map, INVALID_RAILTYPE, sizeof(this->railtype_map));
+ std::fill(std::begin(this->railtype_map), std::end(this->railtype_map), INVALID_RAILTYPE);
this->railtype_map[0] = RAILTYPE_RAIL;
this->railtype_map[1] = RAILTYPE_ELECTRIC;
this->railtype_map[2] = RAILTYPE_MONO;
this->railtype_map[3] = RAILTYPE_MAGLEV;
/* Initialise road type map with default road types */
- memset(this->roadtype_map, INVALID_ROADTYPE, sizeof(this->roadtype_map));
+ std::fill(std::begin(this->roadtype_map), std::end(this->roadtype_map), INVALID_ROADTYPE);
this->roadtype_map[0] = ROADTYPE_ROAD;
/* Initialise tram type map with default tram types */
- memset(this->tramtype_map, INVALID_ROADTYPE, sizeof(this->tramtype_map));
+ std::fill(std::begin(this->tramtype_map), std::end(this->tramtype_map), INVALID_ROADTYPE);
this->tramtype_map[0] = ROADTYPE_TRAM;
/* Copy the initial parameter list