shithub: rgbds

Download patch

ref: 5dd941b311ea5a4d0e873ad0b6a1a0db9ed2aedc
parent: 5ea8490e2b07a110f1aacc8079c850d70cb90058
author: JL2210 <[email protected]>
date: Wed Apr 8 14:38:18 EDT 2020

Fix modulo by zero

Yet another case caught by scan-build:

src/link/patch.c:188:21: warning: Division by zero
                        value = popRPN() % value;
                                ~~~~~~~~~^~~~~~~

Just copy over the code from the division case, with a few modifications.

Signed-off-by: JL2210 <[email protected]>

--- a/src/link/patch.c
+++ b/src/link/patch.c
@@ -185,7 +185,13 @@
 			break;
 		case RPN_MOD:
 			value = popRPN();
-			value = popRPN() % value;
+			if (value == 0) {
+				error("%s: Modulo by 0", patch->fileName);
+				popRPN();
+				value = 0;
+			} else {
+				value = popRPN() % value;
+			}
 			break;
 		case RPN_UNSUB:
 			value = -popRPN();