SaveState: Initialize some memory that is saved.

At the very least, will help them compress better.  Also good not to leak
random memory.
This commit is contained in:
Unknown W. Brackets 2018-06-22 21:25:07 -07:00
parent 3090360692
commit fd8a0612fa
8 changed files with 27 additions and 16 deletions

View File

@ -300,7 +300,7 @@ CChunkFileReader::Error CChunkFileReader::SaveFile(const std::string &filename,
}
// Create header
SChunkHeader header;
SChunkHeader header{};
header.Compress = compressed_buffer ? 1 : 0;
header.Revision = REVISION_CURRENT;
header.ExpectedSize = (u32)write_len;
@ -308,7 +308,7 @@ CChunkFileReader::Error CChunkFileReader::SaveFile(const std::string &filename,
truncate_cpy(header.GitVersion, gitVersion);
// Setup the fixed-length title.
char titleFixed[128];
char titleFixed[128]{};
truncate_cpy(titleFixed, title.c_str());
// Now let's start writing out the file...

View File

@ -46,6 +46,8 @@ public:
head_ = 0;
tail_ = 0;
count_ = 0;
// Not entirely necessary, but keeps things clean.
memset(storage_, 0, sizeof(T) * N);
}
void push(T t) {

View File

@ -160,6 +160,7 @@ void __AudioDoState(PointerWrap &p) {
p.Do(mixFrequency);
// TODO: This never happens because maxVer=1.
if (s >= 2) {
resampler.DoState(p);
} else {

View File

@ -317,6 +317,7 @@ void InterruptState::restore()
void InterruptState::clear()
{
savedCpu.reset();
}
// http://forums.ps2dev.org/viewtopic.php?t=5687

View File

@ -544,7 +544,7 @@ public:
p.Do(currentMipscallId);
p.Do(currentCallbackId);
// TODO: How do I "version" adding a DoState method to ThreadContext?
// TODO: If we want to "version" a DoState method here, we can just use minVer = 0.
p.Do(context);
if (s <= 3)
@ -1824,6 +1824,8 @@ void ThreadContext::reset()
fcr31 = 0x00000e00;
hi = 0xDEADBEEF;
lo = 0xDEADBEEF;
// Just for a clean state.
other[5] = 0;
}
void __KernelResetThread(Thread *t, int lowestPriority)

View File

@ -111,21 +111,21 @@ public:
private:
s16 samples[28];
int curSample;
int curSample = 0;
u32 data_;
u32 read_;
int curBlock_;
int loopStartBlock_;
int numBlocks_;
u32 data_ = 0;
u32 read_ = 0;
int curBlock_ = -1;
int loopStartBlock_ = -1;
int numBlocks_ = 0;
// rolling state. start at 0, should probably reset to 0 on loops?
int s_1;
int s_2;
int s_1 = 0;
int s_2 = 0;
bool loopEnabled_;
bool loopAtNextBlock_;
bool end_;
bool loopEnabled_ = false;
bool loopAtNextBlock_ = false;
bool end_ = false;
};
class SasAtrac3 {

View File

@ -501,5 +501,10 @@ void BlockAllocator::Block::DoState(PointerWrap &p)
p.Do(start);
p.Do(size);
p.Do(taken);
// Since we use truncate_cpy, the empty space is not zeroed. Zero it now.
// This avoids saving uninitialized memory.
size_t tagLen = strlen(tag);
if (tagLen != sizeof(tag))
memset(tag + tagLen, 0, sizeof(tag) - tagLen);
p.DoArray(tag, sizeof(tag));
}

View File

@ -319,8 +319,8 @@ protected:
DisplayList *currentList;
DisplayListQueue dlQueue;
bool interruptRunning;
GPURunState gpuState;
bool interruptRunning = false;
GPURunState gpuState = GPUSTATE_RUNNING;
bool isbreak;
u64 drawCompleteTicks;
u64 busyTicks;