[Scummvm-cvs-logs] scummvm master -> 13cc433fb6c5ba49722092d2463631fbc8dda351

Strangerke Strangerke at scummvm.org
Sun Jun 1 00:19:33 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:
13cc433fb6 CRUISE: error out in some cases where divide by zero is expected


Commit: 13cc433fb6c5ba49722092d2463631fbc8dda351
    https://github.com/scummvm/scummvm/commit/13cc433fb6c5ba49722092d2463631fbc8dda351
Author: Strangerke (strangerke at scummvm.org)
Date: 2014-06-01T00:18:08+02:00

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

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



diff --git a/engines/cruise/font.cpp b/engines/cruise/font.cpp
index 5c04154..2ef43c9 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 75cf428..764a458 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:






More information about the Scummvm-git-logs mailing list