Skip to content

Commit 96eec4f

Browse files
committed
compile: Don't try to constant-fold division by zero.
The way it is, just crashes app. And optimizing to "raise ZeroDivisionError" is probably too much.
1 parent 864038d commit 96eec4f

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

py/compile.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ mp_parse_node_t fold_constants(mp_parse_node_t pn) {
145145
} else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[1], MP_TOKEN_OP_PERCENT)) {
146146
pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, python_modulo(arg0, arg1));
147147
} else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[1], MP_TOKEN_OP_DBL_SLASH)) {
148-
pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, python_floor_divide(arg0, arg1));
148+
if (arg1 != 0) {
149+
pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, python_floor_divide(arg0, arg1));
150+
}
149151
} else {
150152
// shouldn't happen
151153
assert(0);

0 commit comments

Comments
 (0)