All of lore.kernel.org
 help / color / mirror / Atom feed
From: Al Viro <viro@ftp.linux.org.uk>
To: Alexey Dobriyan <adobriyan@gmail.com>
Cc: linux-sparse@vger.kernel.org
Subject: Re: [patchset] rewrite of initializer handling
Date: Tue, 19 Jun 2007 23:33:17 +0100	[thread overview]
Message-ID: <20070619223317.GO21478@ftp.linux.org.uk> (raw)
In-Reply-To: <20070619172143.GM21478@ftp.linux.org.uk>

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);

  reply	other threads:[~2007-06-19 22:33 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-19 17:12 [patchset] rewrite of initializer handling Alexey Dobriyan
2007-06-19 17:21 ` Al Viro
2007-06-19 22:33   ` Al Viro [this message]
  -- strict thread matches above, loose matches on Subject: below --
2007-06-18 10:19 Al Viro
2007-06-18 10:26 ` Al Viro
2007-06-18 17:07 ` Linus Torvalds
2007-06-18 18:02   ` Josh Triplett
2007-06-18 19:30     ` Al Viro
2007-06-18 18:19 ` Josh Triplett
2007-06-18 19:16   ` Al Viro
2007-06-18 19:27     ` Linus Torvalds
2007-06-18 21:46     ` Michael Stefaniuc
2007-06-18 22:43       ` Al Viro
2007-06-19  9:47         ` Michael Stefaniuc
2007-06-19 20:15     ` Michael Stefaniuc
2007-06-19 22:41       ` Al Viro
2007-06-20  8:54         ` Michael Stefaniuc
2007-06-20 21:29           ` Michael Stefaniuc

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070619223317.GO21478@ftp.linux.org.uk \
    --to=viro@ftp.linux.org.uk \
    --cc=adobriyan@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.