[hackers] [scc] [cc1] Do not allow operations with pointers to incomplete types || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Tue, 9 Aug 2016 14:25:44 +0200 (CEST)

commit dfe85dcaa8a0216b88815c0cf67ef247c51dc18c
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Aug 9 14:06:39 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Tue Aug 9 14:06:39 2016 +0200

    [cc1] Do not allow operations with pointers to incomplete types
    
    The only operations allowed with pointers to incomplete types
    is the assignation and the comparition, so we have to catch
    all the rest and give a good error message.

diff --git a/cc1/expr.c b/cc1/expr.c
index 281ac13..21af200 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
_AT_@ -316,7 +316,12 @@ parithmetic(char op, Node *lp, Node *rp)
         if (lp->type->op != PTR)
                 XCHG(lp, rp, np);
 
+ tp = rp->type;
+ if (tp->op == PTR && !(tp->type->prop & TDEFINED))
+ goto incomplete;
         tp = lp->type;
+ if (!(tp->type->prop & TDEFINED))
+ goto incomplete;
         size = sizeofnode(tp->type);
 
         if (op == OSUB && BTYPE(rp) == PTR) {
_AT_@ -334,9 +339,13 @@ parithmetic(char op, Node *lp, Node *rp)
 
         return simplify(OADD, tp, lp, rp);
 
+incomplete:
+ errorp("invalid use of undefined type");
+ return lp;
 incorrect:
         errorp("incorrect arithmetic operands");
- return node(OADD, tp, lp, rp);
+ return lp;
+
 }
 
 static Node *
_AT_@ -542,6 +551,10 @@ incdec(Node *np, char op)
         if (!(tp->prop & TDEFINED)) {
                 errorp("invalid use of undefined type");
                 return np;
+ } else if (tp->op == PTR && !(tp->type->prop & TDEFINED)) {
+ errorp("%s of pointer to an incomplete type",
+ (op == OINC) ? "increment" : "decrement");
+ return np;
         } else if (tp->prop & TARITH) {
                 inc = constnode(one);
         } else if (tp->op == PTR) {
Received on Tue Aug 09 2016 - 14:25:44 CEST

This archive was generated by hypermail 2.3.0 : Tue Aug 09 2016 - 14:36:23 CEST