commit 89db1825e0012c166dc6443493c3ebeac21d49e6
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Wed Aug 26 11:28:09 2015 +0200
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Wed Aug 26 11:33:16 2015 +0200

    Fix types of integer operands in pointer additions
    
    The code was adding things of different type, and it was doing
    casts that were not necessary. This new version does the multiplication
    in size_t type, and convert the result to pointer.

diff --git a/cc1/expr.c b/cc1/expr.c
index 1fc8b39..9ffa3a8 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -457,9 +457,11 @@ parithmetic(char op, Node *lp, Node *rp)
        }
        if (BTYPE(rp) != INT)
                goto incorrect;
-       rp = node(OCAST, tp, promote(rp), NULL);
-       rp = node(OMUL, tp, rp, size);
-       return node(op, tp, lp, rp);
+       rp = convert(promote(rp), sizettype, 0);
+       rp = node(OMUL, sizettype, rp, size);
+       rp = node(OCAST, tp, rp, NULL);
+
+       return node(OADD, tp, lp, rp);
 
 incorrect:
        error("incorrect arithmetic operands");

Reply via email to