(svn r9837) -Fix: [NewGRF] Catch occurance of division-by-zero in varaction handling.
authorpeter1138
Mon, 14 May 2007 17:37:34 +0000
changeset 7113 4b0fd37ee609
parent 7112 fcac9e881b43
child 7114 665294e21ae8
(svn r9837) -Fix: [NewGRF] Catch occurance of division-by-zero in varaction handling.
src/newgrf_spritegroup.cpp
--- a/src/newgrf_spritegroup.cpp	Mon May 14 16:07:05 2007 +0000
+++ b/src/newgrf_spritegroup.cpp	Mon May 14 17:37:34 2007 +0000
@@ -129,10 +129,10 @@
 		case DSGA_OP_SMAX: return max((S)last_value, (S)value);
 		case DSGA_OP_UMIN: return min((U)last_value, (U)value);
 		case DSGA_OP_UMAX: return max((U)last_value, (U)value);
-		case DSGA_OP_SDIV: return (S)last_value / (S)value;
-		case DSGA_OP_SMOD: return (S)last_value % (S)value;
-		case DSGA_OP_UDIV: return (U)last_value / (U)value;
-		case DSGA_OP_UMOD: return (U)last_value % (U)value;
+		case DSGA_OP_SDIV: return value == 0 ? (S)last_value : (S)last_value / (S)value;
+		case DSGA_OP_SMOD: return value == 0 ? (S)last_value : (S)last_value % (S)value;
+		case DSGA_OP_UDIV: return value == 0 ? (U)last_value : (U)last_value / (U)value;
+		case DSGA_OP_UMOD: return value == 0 ? (U)last_value : (U)last_value % (U)value;
 		case DSGA_OP_MUL:  return last_value * value;
 		case DSGA_OP_AND:  return last_value & value;
 		case DSGA_OP_OR:   return last_value | value;