# [hackers] [scc] Concentrate all the division by 0 in only one place || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Wed, 2 Sep 2015 18:25:57 +0200 (CEST)

commit 19e83e69aa412cea8f41a28506cc9bfcc84525c4
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Wed Sep 2 14:56:56 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Wed Sep 2 17:02:34 2015 +0200

Concentrate all the division by 0 in only one place

diff --git a/cc1/fold.c b/cc1/fold.c
index 8d2e486..45d5a20 100644
--- a/cc1/fold.c
+++ b/cc1/fold.c
_AT_@ -93,11 +93,7 @@ divi(TINT l, TINT r, Type *tp)
{
struct limits *lim = getlimits(tp);

- if (r == 0) {
- warn("division by 0");
- return 0;
- }
- if (l == lim->min.i && r == -1) {
+ if (r == 0 || l == lim->min.i && r == -1) {
warn("overflow in constant expression");
return 0;
}
_AT_@ -112,11 +108,7 @@ divf(TFLOAT l, TFLOAT r, Type *tp)
if (l < 0) l = -l;
if (r < 0) r = -r;

- if (r == 0.0) {
- warn("division by 0");
- return 0;
- }
- if (r < 1.0 && l > lim->max.f * r) {
+ if (r == 0.0 || r < 1.0 && l > lim->max.f * r) {
warn("overflow in constant expression");
return 0;
}
_AT_@ -308,8 +300,13 @@ fold(int op, Type *tp, Node *lp, Node *rp)
Node *np;
int type;

+ if ((op == ODIV || op == OMOD) && cmpnode(rp, 0)) {
+ warn("division by 0");
+ return NULL;
+ }
if (!lp->constant || rp && !rp->constant)
return NULL;
+
ls = lp->sym;
rs = (rp) ? rp->sym : NULL;

_AT_@ -416,9 +413,9 @@ simplify(int op, Type *tp, Node *lp, Node *rp)
{
Node *np;

+ commutative(&op, &lp, &rp);
if ((np = fold(op, tp, lp, rp)) != NULL)
return np;
- commutative(&op, &lp, &rp);
if ((np = identity(op, lp, rp)) != NULL)
return np;
return node(op, tp, lp, rp);
Received on Wed Sep 02 2015 - 18:25:57 CEST

This archive was generated by hypermail 2.3.0 : Wed Sep 02 2015 - 18:36:13 CEST