CRUISE: error out in some cases where divide by zero is expected

This commit is contained in:
Strangerke 2014-06-01 00:18:08 +02:00
parent 60c0de6200
commit 13cc433fb6
2 changed files with 12 additions and 4 deletions

View File

@ -50,7 +50,7 @@ int32 getLineHeight(int16 charCount, const FontEntry *fontPtr) {
}
/**
* This function determins how many lines the text will have
* This function determines how many lines the text will have
*/
int32 getTextLineCount(int32 rightBorder_X, int16 wordSpacingWidth,
const FontEntry *fontData, const char *textString) {
@ -59,6 +59,9 @@ int32 getTextLineCount(int32 rightBorder_X, int16 wordSpacingWidth,
uint8 ch;
int32 total = 0, lineLength = 0;
if (rightBorder_X == 0)
error("getTextLineCount() - invalid parameter");
if (!*textString)
return (0);
@ -89,7 +92,8 @@ int32 getTextLineCount(int32 rightBorder_X, int16 wordSpacingWidth,
if (lineLength > 0)
total += rightBorder_X;
return (total / (rightBorder_X == 0 ? 1 : rightBorder_X));
return (total / rightBorder_X);
}
void loadFNT(const char *fileName) {

View File

@ -415,7 +415,9 @@ int32 opcodeType3() { // math
return (0);
}
case 1: {
pushVar(pop1 / (pop2 == 0 ? 1 : pop2));
if (pop2 == 0)
error("opcodeType3 - Invalid value for pop2");
pushVar(pop1 / pop2);
return (0);
}
case 2: {
@ -427,7 +429,9 @@ int32 opcodeType3() { // math
return (0);
}
case 4: {
pushVar(pop1 % (pop2 == 0 ? 1 : pop2));
if (pop2 == 0)
error("opcodeType3 - Invalid value for pop2");
pushVar(pop1 % pop2);
return (0);
}
case 7: