Fix some undefined behavior

The destructor of Resampler needs to be virtual, as it is subclassed
and pointers to objects subclassed from it are being deleted.

The issue in controls.cpp is that the loop ends up reading past the
end of an array. The small rewrite of the loop also makes it more
readable.

In memmap.cpp, there is an assignment statement of the following form:
	a[i++] = b[i];
It is undefined what i's value should be in b[i], so this was made
explicit.
This commit is contained in:
Ari Sundholm 2017-09-09 14:12:33 +03:00
parent 4080eef6a7
commit 60aabb91d7
3 changed files with 9 additions and 4 deletions

View File

@ -17,7 +17,7 @@ class Resampler : public ring_buffer
{
}
~Resampler ()
virtual ~Resampler ()
{
}

View File

@ -2879,8 +2879,9 @@ void S9xSetJoypadLatch (bool latch)
switch (i = curcontrollers[n])
{
case MP5:
for (int j = 0, k = mp5[n].pads[j]; j < 4; k = mp5[n].pads[++j])
for (int j = 0, k; j < 4; ++j)
{
k = mp5[n].pads[j];
if (k == NONE)
continue;
do_polling(k);
@ -3170,8 +3171,9 @@ void S9xControlEOF (void)
switch (i = curcontrollers[n])
{
case MP5:
for (j = 0, i = mp5[n].pads[j]; j < 4; i = mp5[n].pads[++j])
for (j = 0; j < 4; ++j)
{
i = mp5[n].pads[j];
if (i == NONE)
continue;

View File

@ -4054,7 +4054,10 @@ static bool8 ReadBPSPatch (Stream *r, long, int32 &rom_size)
switch((int)mode) {
case SourceRead:
while(length--) patched_rom[outputOffset++] = Memory.ROM[outputOffset];
while(length--) {
patched_rom[outputOffset] = Memory.ROM[outputOffset];
outputOffset++;
}
break;
case TargetRead:
while(length--) patched_rom[outputOffset++] = data[addr++];