summaryrefslogtreecommitdiff
path: root/parse/fold.c
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-02-08 14:28:06 -0800
committerOri Bernstein <ori@eigenstate.org>2016-02-08 14:42:07 -0800
commit1342e9853431adbf651c5a867396c02f87d51144 (patch)
treee407111342a2633dd8e78fc8f5a707cb194945fb /parse/fold.c
parentde19a8fec7353f9e81a3c4660dd314d5cd15fd02 (diff)
downloadmc-1342e9853431adbf651c5a867396c02f87d51144.tar.gz
Fix mistake in folding.
x % 0 is crash. x % 1 is 0.
Diffstat (limited to 'parse/fold.c')
-rw-r--r--parse/fold.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/parse/fold.c b/parse/fold.c
index 02b37e2..8edd836 100644
--- a/parse/fold.c
+++ b/parse/fold.c
@@ -182,9 +182,12 @@ Node *fold(Node *n, int foldvar)
r = val(n->loc, a / b, exprtype(n));
break;
case Omod:
- /* x%1 = x */
+ /* x%0 = error */
if (isintval(args[1], 0))
- r = args[0];
+ fatal(args[1], "division by zero");
+ /* x%1 = 0 */
+ if (isintval(args[1], 1))
+ r = val(n->loc, 0, exprtype(n));
if (getintlit(args[0], &a) && getintlit(args[1], &b))
r = val(n->loc, a % b, exprtype(n));
break;