diff mbox

[bug,bisected,-chrisl] Segfault at evaluate.c:341

Message ID 20090321172823.GA5509@ZenIV.linux.org.uk (mailing list archive)
State Mainlined, archived
Headers show

Commit Message

Al Viro March 21, 2009, 5:28 p.m. UTC
On Sat, Mar 21, 2009 at 04:40:20AM +0000, Al Viro wrote:
> On Thu, Mar 19, 2009 at 04:11:41PM -0700, Christopher Li wrote:
> > Thanks Al,
> > 
> > I will apply it later tonight.
> > 
> > If no one beats to me, I will try to add the warning for using preprocessor
> > directive inside macro expansion. It should be a better error message
> > than the current one.
> 
> Well...  patch below would give more or less close approximation to the
> current set of nasal demons produced by gcc in these situations + error
> when that crap happens.
> Warning: it might make things slower, and it needs testing.
> 
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> ---

It needed testing, all right - #elif handling got broken by the initial
variant...  Hopefully fixed version follows:

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Christopher Li March 23, 2009, 9:22 a.m. UTC | #1
>
> It needed testing, all right - #elif handling got broken by the initial
> variant...  Hopefully fixed version follows:

Looks good. BTW, it is simpler than my version which try to do
the processor in argument list.

Applied, thanks.

Chris
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/pre-process.c b/pre-process.c
index cf53893..34b21ff 100644
--- a/pre-process.c
+++ b/pre-process.c
@@ -193,13 +193,36 @@  static void expand_list(struct token **list)
 	}
 }
 
+static void preprocessor_line(struct stream *stream, struct token **line);
+
 static struct token *collect_arg(struct token *prev, int vararg, struct position *pos)
 {
+	struct stream *stream = input_streams + prev->pos.stream;
 	struct token **p = &prev->next;
 	struct token *next;
 	int nesting = 0;
 
 	while (!eof_token(next = scan_next(p))) {
+		if (next->pos.newline && match_op(next, '#')) {
+			if (!next->pos.noexpand) {
+				sparse_error(next->pos,
+					     "directive in argument list");
+				preprocessor_line(stream, p);
+				__free_token(next);	/* Free the '#' token */
+				continue;
+			}
+		}
+		switch (token_type(next)) {
+		case TOKEN_STREAMEND:
+		case TOKEN_STREAMBEGIN:
+			*p = &eof_token_entry;
+			return next;
+		}
+		if (false_nesting) {
+			*p = next->next;
+			__free_token(next);
+			continue;
+		}
 		if (match_op(next, '(')) {
 			nesting++;
 		} else if (match_op(next, ')')) {
@@ -1357,8 +1380,9 @@  static int handle_elif(struct stream * stream, struct token **line, struct token
 	if (token_type(top_if) != TOKEN_IF)
 		return 1;
 	if (false_nesting) {
-		if (expression_value(&token->next))
-			false_nesting = 0;
+		false_nesting = 0;
+		if (!expression_value(&token->next))
+			false_nesting = 1;
 	} else {
 		false_nesting = 1;
 		token_type(top_if) = TOKEN_SKIP_GROUPS;