summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2016-12-10 13:26:29 +0000
committerfrosch <frosch@openttd.org>2016-12-10 13:26:29 +0000
commit3ee06b036ea2e6b511a911bc77d5758413584402 (patch)
tree0b3b3b73d2d414ef75d32090aa177c8f5fc26696
parent10293c5fb1b90dcf13847fd07e44534550f1d656 (diff)
downloadopenttd-3ee06b036ea2e6b511a911bc77d5758413584402.tar.xz
(svn r27687) -Fix: RailtypeInfo::alternate_labels leaked when reloading NewGRF. (adf88)
-rw-r--r--src/rail.h3
-rw-r--r--src/rail_cmd.cpp15
2 files changed, 9 insertions, 9 deletions
diff --git a/src/rail.h b/src/rail.h
index 320d24a9a..1bc403d7f 100644
--- a/src/rail.h
+++ b/src/rail.h
@@ -113,7 +113,8 @@ typedef SmallVector<RailTypeLabel, 4> RailTypeLabelList;
/**
* This struct contains all the info that is needed to draw and construct tracks.
*/
-struct RailtypeInfo {
+class RailtypeInfo {
+public:
/**
* Struct containing the main sprites. @note not all sprites are listed, but only
* the ones used directly in the code
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index d6c9194de..8348d7da9 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -47,8 +47,6 @@ RailtypeInfo _railtypes[RAILTYPE_END];
RailType _sorted_railtypes[RAILTYPE_END];
uint8 _sorted_railtypes_size;
-assert_compile(sizeof(_original_railtypes) <= sizeof(_railtypes));
-
/** Enum holding the signal offset in the sprite sheet according to the side it is representing. */
enum SignalOffsets {
SIGNAL_TO_SOUTHWEST,
@@ -66,8 +64,11 @@ enum SignalOffsets {
*/
void ResetRailTypes()
{
- memset(_railtypes, 0, sizeof(_railtypes));
- memcpy(_railtypes, _original_railtypes, sizeof(_original_railtypes));
+ assert_compile(lengthof(_original_railtypes) <= lengthof(_railtypes));
+
+ uint i = 0;
+ for (; i < lengthof(_original_railtypes); i++) _railtypes[i] = _original_railtypes[i];
+ for (; i < lengthof(_railtypes); i++) _railtypes[i] = RailtypeInfo(); // zero-init
}
void ResolveRailTypeGUISprites(RailtypeInfo *rti)
@@ -151,11 +152,9 @@ RailType AllocateRailType(RailTypeLabel label)
if (rti->label == 0) {
/* Set up new rail type */
- memcpy(rti, &_railtypes[RAILTYPE_RAIL], sizeof(*rti));
+ *rti = _railtypes[RAILTYPE_RAIL];
rti->label = label;
- /* Clear alternate label list. Can't use Reset() here as that would free
- * the data pointer of RAILTYPE_RAIL and not our new rail type. */
- new (&rti->alternate_labels) RailTypeLabelList;
+ rti->alternate_labels.Clear();
/* Make us compatible with ourself. */
rti->powered_railtypes = (RailTypes)(1 << rt);