[hackers] [scc] Fix types of integer operands in pointer additions || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Wed, 26 Aug 2015 22:32:48 +0200 (CEST)

commit 89db1825e0012c166dc6443493c3ebeac21d49e6
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Wed Aug 26 11:28:09 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
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
_AT_@ -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");
Received on Wed Aug 26 2015 - 22:32:48 CEST

This archive was generated by hypermail 2.3.0 : Wed Aug 26 2015 - 22:36:14 CEST