commit 96c513c259241630f8397815acfc4da6fcb57237
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Thu Feb 23 10:06:58 2017 +0100
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Thu Feb 23 10:06:58 2017 +0100

    [cc1] Fix pointer substraction with void*
    
    At this moment the code was strictly checking if the two
    pointers involved in a substraction had the same type,
    but this was an error because substracting any pointer
    with a null pointer should be allowed.

diff --git a/cc1/expr.c b/cc1/expr.c
index eb91a8e..fed3300 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -304,7 +304,7 @@ parithmetic(int op, Node *lp, Node *rp)
        size = sizeofnode(tp->type);
 
        if (op == OSUB && BTYPE(rp) == PTR) {
-               if (!eqtype(tp, rp->type, 0))
+               if ((rp = convert(rp, lp->type, 0)) == NULL)
                        goto incorrect;
                lp = node(OSUB, pdifftype, lp, rp);
                return node(ODIV, inttype, lp, size);

Reply via email to