summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2014-09-13 14:46:03 +0000
committerfrosch <frosch@openttd.org>2014-09-13 14:46:03 +0000
commite53d97b4f8fa04d5294e6cb5737cbe23e4339130 (patch)
tree91e124a92b3940a211fede83bc3a6288f9b77a06
parent61e129cc22d1eab769d368d9e68a257a19db743d (diff)
downloadopenttd-e53d97b4f8fa04d5294e6cb5737cbe23e4339130.tar.xz
(svn r26816) -Fix [FS#6109]: Properly zero-initialise data in _temp_engine.
-rw-r--r--src/saveload/engine_sl.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/saveload/engine_sl.cpp b/src/saveload/engine_sl.cpp
index af53e4006..df4aa37b9 100644
--- a/src/saveload/engine_sl.cpp
+++ b/src/saveload/engine_sl.cpp
@@ -13,7 +13,7 @@
#include "saveload_internal.h"
#include "../engine_base.h"
#include "../string_func.h"
-#include <map>
+#include <vector>
#include "../safeguards.h"
@@ -48,11 +48,24 @@ static const SaveLoad _engine_desc[] = {
SLE_END()
};
-static std::map<EngineID, Engine> _temp_engine;
+static std::vector<Engine> _temp_engine;
Engine *GetTempDataEngine(EngineID index)
{
- return &_temp_engine[index];
+ if (index < _temp_engine.size()) {
+ return &_temp_engine[index];
+ } else if (index == _temp_engine.size()) {
+ uint8 zero[sizeof(Engine)];
+ memset(zero, 0, sizeof(zero));
+ Engine *engine = new (zero) Engine();
+
+ /* Adding 'engine' to the vector makes a shallow copy, so we do not want to destruct 'engine' */
+ _temp_engine.push_back(*engine);
+
+ return &_temp_engine[index];
+ } else {
+ NOT_REACHED();
+ }
}
static void Save_ENGN()