Fix missing bounds checking, reported by Coverity.

This area of the code could also use some named constants, which are also used in DeveloperDialog.
This commit is contained in:
Stephen Anthony 2019-11-30 22:06:38 -03:30
parent f3e2c401c0
commit 8bf39568ab
2 changed files with 8 additions and 3 deletions

View File

@ -41,11 +41,15 @@ void RewindManager::setup()
const string& prefix = myOSystem.settings().getBool("dev.settings") ? "dev." : "plr.";
mySize = myOSystem.settings().getInt(prefix + "tm.size");
// TODO - Add proper bounds checking (define constexpr variables for this)
// Use those bounds in DeveloperDialog too
mySize = std::min<uInt32>(
myOSystem.settings().getInt(prefix + "tm.size"), MAX_BUF_SIZE);
if(mySize != myStateList.capacity())
resize(mySize);
myUncompressed = myOSystem.settings().getInt(prefix + "tm.uncompressed");
myUncompressed = std::min<uInt32>(
myOSystem.settings().getInt(prefix + "tm.uncompressed"), MAX_BUF_SIZE);
myInterval = INTERVAL_CYCLES[0];
for(int i = 0; i < NUM_INTERVALS; ++i)
@ -238,7 +242,7 @@ string RewindManager::saveAllStates()
return "Can't save to all states file";
uInt32 curIdx = getCurrentIdx();
rewindStates(1000);
rewindStates(MAX_BUF_SIZE);
uInt32 numStates = uInt32(cyclesList().size());
// Save header

View File

@ -49,6 +49,7 @@ class RewindManager
RewindManager(OSystem& system, StateManager& statemgr);
public:
static constexpr uInt32 MAX_BUF_SIZE = 1000;
static constexpr int NUM_INTERVALS = 7;
// cycle values for the intervals
const uInt32 INTERVAL_CYCLES[NUM_INTERVALS] = {