CRUISE: Add a couple of safeguards to avoid potential division by zero

This commit is contained in:
Strangerke 2014-05-31 18:05:54 +02:00
parent e8a52b67e8
commit 6283e7f423
3 changed files with 5 additions and 7 deletions

View File

@ -89,7 +89,7 @@ int32 getTextLineCount(int32 rightBorder_X, int16 wordSpacingWidth,
if (lineLength > 0)
total += rightBorder_X;
return (total / rightBorder_X);
return (total / (rightBorder_X == 0 ? 1 : rightBorder_X));
}
void loadFNT(const char *fileName) {

View File

@ -87,9 +87,7 @@ int16 Op_Exec() {
int numOfArgToPop = popVar();
int i = 0;
for (i = 0; i < numOfArgToPop; i++) {
for (int i = 0; i < numOfArgToPop; i++) {
popTable[numOfArgToPop - i - 1] = popVar();
}
@ -111,7 +109,7 @@ int16 Op_Exec() {
ptr2 = ptr;
for (i = 0; i < numOfArgToPop; i++) {
for (int i = 0; i < numOfArgToPop; i++) {
WRITE_BE_UINT16(ptr2, popTable[i]);
ptr2 += 2;
}

View File

@ -415,7 +415,7 @@ int32 opcodeType3() { // math
return (0);
}
case 1: {
pushVar(pop1 / pop2);
pushVar(pop1 / (pop2 == 0 ? 1 : pop2));
return (0);
}
case 2: {
@ -427,7 +427,7 @@ int32 opcodeType3() { // math
return (0);
}
case 4: {
pushVar(pop1 % pop2);
pushVar(pop1 % (pop2 == 0 ? 1 : pop2));
return (0);
}
case 7: