[hackers] [scc] [cc1] Fix pointer substraction with void* || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Thu, 23 Feb 2017 10:12:11 +0100 (CET)

commit 96c513c259241630f8397815acfc4da6fcb57237
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Thu Feb 23 10:06:58 2017 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
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
_AT_@ -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);
Received on Thu Feb 23 2017 - 10:12:11 CET

This archive was generated by hypermail 2.3.0 : Thu Feb 23 2017 - 10:24:15 CET