On Tue, Jun 19, 2007 at 06:21:43PM +0100, Al Viro wrote:
> Gaack...  The fix is obvious (add e && into that condition and into
> e->type == EXPR_STRING a couple of lines below), but...  I wonder
> if adding EXPR_BAD and using it to deal with such crap in parser
> would be better.  Comments?

Anyway, brute-force patch follows.  I still suspect that long-term
we will be better off with explicit EXPR_BAD nodes and guaranteed
things like "->unop of EXPR_PREOP is never NULL", but that can be
done separately - a lot of checks for NULL will be possible to remove.

diff --git a/evaluate.c b/evaluate.c
--- a/evaluate.c
+++ b/evaluate.c
@@ -2029,6 +2029,10 @@ static struct expression *check_designators(struct 
expression *e,
                        e->ctype = ctype = type;
                        ctype = type;
                        last = e;
+                       if (!e->idx_expression) {
+                               err = "invalid";
+                               break;
+                       }
                        e = e->idx_expression;
                } else if (e->type == EXPR_IDENTIFIER) {
                        if (ctype->type != SYM_STRUCT && ctype->type != 
SYM_UNION) {
@@ -2042,6 +2046,10 @@ static struct expression *check_designators(struct 
expression *e,
                        }
                        e->field = e->ctype = ctype;
                        last = e;
+                       if (!e->ident_expression) {
+                               err = "invalid";
+                               break;
+                       }
                        e = e->ident_expression;
                } else if (e->type == EXPR_POS) {
                        err = "internal front-end error: EXPR_POS in";
@@ -2203,9 +2211,9 @@ found:
 static int is_string_literal(struct expression **v)
 {
        struct expression *e = *v;
-       while (e->type == EXPR_PREOP && e->op == '(')
+       while (e && e->type == EXPR_PREOP && e->op == '(')
                e = e->unop;
-       if (e->type != EXPR_STRING)
+       if (!e || e->type != EXPR_STRING)
                return 0;
        if (e != *v && Wparen_string)
                warning(e->pos,
@@ -2274,6 +2282,9 @@ static int handle_simple_initializer(struct expression 
**ep, int nested,
        struct expression *e = *ep, *p;
        struct symbol *type;
 
+       if (!e)
+               return 0;
+
        /* scalar */
        if (!(class & TYPE_COMPOUND)) {
                e = handle_scalar(e, nested);
-
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to