aboutsummaryrefslogtreecommitdiff
path: root/engines/cruise
diff options
context:
space:
mode:
authorStrangerke2014-06-01 00:18:08 +0200
committerStrangerke2014-06-01 00:18:08 +0200
commit13cc433fb6c5ba49722092d2463631fbc8dda351 (patch)
tree51ac6d4f3954574440ccb9c81543f88013bd9297 /engines/cruise
parent60c0de620091c083051555a3ce79680a0bef9abb (diff)
downloadscummvm-rg350-13cc433fb6c5ba49722092d2463631fbc8dda351.tar.gz
scummvm-rg350-13cc433fb6c5ba49722092d2463631fbc8dda351.tar.bz2
scummvm-rg350-13cc433fb6c5ba49722092d2463631fbc8dda351.zip
CRUISE: error out in some cases where divide by zero is expected
Diffstat (limited to 'engines/cruise')
-rw-r--r--engines/cruise/font.cpp8
-rw-r--r--engines/cruise/script.cpp8
2 files changed, 12 insertions, 4 deletions
diff --git a/engines/cruise/font.cpp b/engines/cruise/font.cpp
index 5c04154b01..2ef43c952a 100644
--- a/engines/cruise/font.cpp
+++ b/engines/cruise/font.cpp
@@ -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) {
diff --git a/engines/cruise/script.cpp b/engines/cruise/script.cpp
index 75cf428787..764a458b8f 100644
--- a/engines/cruise/script.cpp
+++ b/engines/cruise/script.cpp
@@ -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: