Merge pull request #880 from PCSX2/coverity-negative-index-array

pcsx2: forbid negative index of array in case of register allocation failure
This commit is contained in:
refractionpcsx2 2015-10-12 20:52:28 +01:00
commit b3d9feb1f2
2 changed files with 19 additions and 3 deletions

View File

@ -133,7 +133,7 @@ int _getFreeXMMreg()
_freeXMMreg(tempi);
return tempi;
}
Console.Error("*PCSX2*: XMM Reg Allocation Error in _getFreeXMMreg()!");
pxFailDev("*PCSX2*: XMM Reg Allocation Error in _getFreeXMMreg()!");
return -1;
}
@ -144,6 +144,9 @@ int _allocTempXMMreg(XMMSSEType type, int xmmreg) {
else
_freeXMMreg(xmmreg);
if (xmmreg == -1)
return -1;
xmmregs[xmmreg].inuse = 1;
xmmregs[xmmreg].type = XMMTYPE_TEMP;
xmmregs[xmmreg].needed = 1;
@ -191,6 +194,9 @@ int _allocVFtoXMMreg(VURegs *VU, int xmmreg, int vfreg, int mode) {
else
_freeXMMreg(xmmreg);
if (xmmreg == -1)
return -1;
g_xmmtypes[xmmreg] = XMMT_FPS;
xmmregs[xmmreg].inuse = 1;
xmmregs[xmmreg].type = XMMTYPE_VFREG;
@ -273,6 +279,9 @@ int _allocACCtoXMMreg(VURegs *VU, int xmmreg, int mode) {
else
_freeXMMreg(xmmreg);
if (xmmreg == -1)
return -1;
g_xmmtypes[xmmreg] = XMMT_FPS;
xmmregs[xmmreg].inuse = 1;
xmmregs[xmmreg].type = XMMTYPE_ACC;
@ -314,6 +323,7 @@ int _allocFPtoXMMreg(int xmmreg, int fpreg, int mode) {
}
if (xmmreg == -1) xmmreg = _getFreeXMMreg();
if (xmmreg == -1) return -1;
g_xmmtypes[xmmreg] = XMMT_FPS;
xmmregs[xmmreg].inuse = 1;
@ -379,6 +389,7 @@ int _allocGPRtoXMMreg(int xmmreg, int gprreg, int mode)
}
if (xmmreg == -1) xmmreg = _getFreeXMMreg();
if (xmmreg == -1) return -1;
g_xmmtypes[xmmreg] = XMMT_INT;
xmmregs[xmmreg].inuse = 1;
@ -455,9 +466,10 @@ int _allocFPACCtoXMMreg(int xmmreg, int mode)
return i;
}
if (xmmreg == -1) {
if (xmmreg == -1)
xmmreg = _getFreeXMMreg();
}
if (xmmreg == -1)
return -1;
g_xmmtypes[xmmreg] = XMMT_FPS;
xmmregs[xmmreg].inuse = 1;

View File

@ -311,6 +311,9 @@ int _allocX86reg(int x86reg, int type, int reg, int mode)
else
_freeX86reg(x86reg);
if (x86reg == -1)
return -1;
x86regs[x86reg].type = type;
x86regs[x86reg].reg = reg;
x86regs[x86reg].mode = mode;
@ -584,6 +587,7 @@ int _allocMMXreg(int mmxreg, int reg, int mode)
}
if (mmxreg == -1) mmxreg = _getFreeMMXreg();
if (mmxreg == -1) return -1;
mmxregs[mmxreg].inuse = 1;
mmxregs[mmxreg].reg = reg;