f0ad3d5458ca8f5ee0d890d64c8de3e5dae61cc4 — Simon Ser 15 days ago 99e5da4
shell/arithm: fix crash on division by zero

Print an error instead.
1 files changed, 10 insertions(+), 0 deletions(-)

M shell/arithm.c
M shell/arithm.c => shell/arithm.c +10 -0
@@ 38,9 38,19 @@ static bool run_arithm_binop(struct mrsh_state *state,
 		*result = left * right;
 		return true;
 	case MRSH_ARITHM_BINOP_SLASH:
+		if (right == 0) {
+			fprintf(stderr, "%s: division by zero: %ld/%ld\n",
+				state->frame->argv[0], left, right);
+			return false;
+		}
 		*result = left / right;
 		return true;
 	case MRSH_ARITHM_BINOP_PERCENT:
+		if (right == 0) {
+			fprintf(stderr, "%s: division by zero: %ld%%%ld\n",
+				state->frame->argv[0], left, right);
+			return false;
+		}
 		*result = left % right;
 		return true;
 	case MRSH_ARITHM_BINOP_PLUS: