scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit c21d1c13987c7082c5157726dcfa4f9715773c5d
parent 0bb819c2423f68687ac0a6376ce6f1a6967a5a51
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 21 Feb 2017 17:08:45 +0100

[cc1] Fix pcompare() with NULL operands

Pcompare() was using eqtype() to see if the type of the operands
were compatible, but this is an error because a null pointer
can be compared to any pointer. For this reason the correct
code must use convert() which currently deals with all the
possible combinations

Diffstat:
Mcc1/expr.c | 19++++++-------------
Mtests/execute/scc-tests.lst | 1+
2 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/cc1/expr.c b/cc1/expr.c @@ -351,23 +351,16 @@ arithmetic(int op, Node *lp, Node *rp) static Node * pcompare(int op, Node *lp, Node *rp) { - Node *np; - int err = 0; + Node *np, *p; if (lp->type->prop & TINTEGER) XCHG(lp, rp, np); + else if (eqtype(lp->type, pvoidtype, 1)) + XCHG(lp, rp, np); - if (rp->type->prop & TINTEGER) { - if (!cmpnode(rp, 0)) - err = 1; - rp = convert(rp, pvoidtype, 1); - } else if (rp->type->op == PTR) { - if (!eqtype(lp->type, rp->type, 1)) - err = 1; - } else { - err = 1; - } - if (err) + if ((p = convert(rp, lp->type, 0)) != NULL) + rp = p; + else errorp("incompatible types in comparison"); return node(op, inttype, lp, rp); } diff --git a/tests/execute/scc-tests.lst b/tests/execute/scc-tests.lst @@ -105,3 +105,4 @@ 0112-cond.c 0113-externredecl.c 0114-shortassig.c +0115-null-comparision.c