aboutsummaryrefslogtreecommitdiff
path: root/engines/cruise
diff options
context:
space:
mode:
authorStrangerke2014-05-31 18:05:54 +0200
committerStrangerke2014-05-31 18:06:32 +0200
commit6283e7f423509aef5a6d37a61f4c664149e55b5f (patch)
tree0fbf1545312357e4ef543cd274dac48065d0f695 /engines/cruise
parente8a52b67e848172066a384ba1c116683177a8415 (diff)
downloadscummvm-rg350-6283e7f423509aef5a6d37a61f4c664149e55b5f.tar.gz
scummvm-rg350-6283e7f423509aef5a6d37a61f4c664149e55b5f.tar.bz2
scummvm-rg350-6283e7f423509aef5a6d37a61f4c664149e55b5f.zip
CRUISE: Add a couple of safeguards to avoid potential division by zero
Diffstat (limited to 'engines/cruise')
-rw-r--r--engines/cruise/font.cpp2
-rw-r--r--engines/cruise/function.cpp6
-rw-r--r--engines/cruise/script.cpp4
3 files changed, 5 insertions, 7 deletions
diff --git a/engines/cruise/font.cpp b/engines/cruise/font.cpp
index 80fb0e8a02..5c04154b01 100644
--- a/engines/cruise/font.cpp
+++ b/engines/cruise/font.cpp
@@ -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) {
diff --git a/engines/cruise/function.cpp b/engines/cruise/function.cpp
index 327dec4d6c..e0053ec017 100644
--- a/engines/cruise/function.cpp
+++ b/engines/cruise/function.cpp
@@ -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;
}
diff --git a/engines/cruise/script.cpp b/engines/cruise/script.cpp
index 65da84b9ce..75cf428787 100644
--- a/engines/cruise/script.cpp
+++ b/engines/cruise/script.cpp
@@ -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: