[hackers] [scc] [cc1] Fix pcompare() with NULL operands || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Tue, 21 Feb 2017 17:11:26 +0100 (CET)

commit c21d1c13987c7082c5157726dcfa4f9715773c5d
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Feb 21 17:08:45 2017 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Tue Feb 21 17:08:45 2017 +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

diff --git a/cc1/expr.c b/cc1/expr.c
index fbbbafc..e99932d 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
_AT_@ -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
index 4e8947d..9e66e0f 100644
--- a/tests/execute/scc-tests.lst
+++ b/tests/execute/scc-tests.lst
_AT_@ -105,3 +105,4 @@
 0112-cond.c
 0113-externredecl.c
 0114-shortassig.c
+0115-null-comparision.c
Received on Tue Feb 21 2017 - 17:11:26 CET

This archive was generated by hypermail 2.3.0 : Tue Feb 21 2017 - 17:12:21 CET