From 96eec4f8a6721bc909415fd3c813757cc50eab7f Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 31 Mar 2014 02:16:25 +0300 Subject: [PATCH] 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. --- py/compile.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/py/compile.c b/py/compile.c index c6c6752d16..89ca380aab 100644 --- a/py/compile.c +++ b/py/compile.c @@ -145,7 +145,9 @@ mp_parse_node_t fold_constants(mp_parse_node_t pn) { } else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[1], MP_TOKEN_OP_PERCENT)) { pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, python_modulo(arg0, arg1)); } else if (MP_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[1], MP_TOKEN_OP_DBL_SLASH)) { - pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, python_floor_divide(arg0, arg1)); + if (arg1 != 0) { + pn = mp_parse_node_new_leaf(MP_PARSE_NODE_SMALL_INT, python_floor_divide(arg0, arg1)); + } } else { // shouldn't happen assert(0);