mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 14:27:16 +00:00
(svn r26816) -Fix [FS#6109]: Properly zero-initialise data in _temp_engine.
This commit is contained in:
parent
61e129cc22
commit
e53d97b4f8
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user