[Scummvm-cvs-logs] scummvm master -> 6283e7f423509aef5a6d37a61f4c664149e55b5f

Strangerke Strangerke at scummvm.org
Sat May 31 18:08:58 CEST 2014


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

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


Commit: 6283e7f423509aef5a6d37a61f4c664149e55b5f
    https://github.com/scummvm/scummvm/commit/6283e7f423509aef5a6d37a61f4c664149e55b5f
Author: Strangerke (strangerke at scummvm.org)
Date: 2014-05-31T18:06:32+02:00

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

Changed paths:
    engines/cruise/font.cpp
    engines/cruise/function.cpp
    engines/cruise/script.cpp



diff --git a/engines/cruise/font.cpp b/engines/cruise/font.cpp
index 80fb0e8..5c04154 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 327dec4..e0053ec 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 65da84b..75cf428 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:






More information about the Scummvm-git-logs mailing list