The problem is here:

                if (match_op(next, '=')) {
                        struct expression *expr;
                        next = constant_expression(next->next, &expr);
                        lastval = get_expression_value(expr);
                        ctype = expr->ctype; <---------- ctype is NULL
                } else if (!ctype) {

And later on it use ctype->type and get a segment fault.

You can try the following quick and dirty patch to fix the problem.

However, to fix the problem right, the get_expression_value() should be
able to indicate error instead of blindly return zero.

Chris

Index: sparse-be/parse.c
===================================================================
--- sparse-be.orig/parse.c      2005-02-18 02:56:50.000000000 -0500
+++ sparse-be/parse.c   2005-02-28 16:54:11.000000000 -0500
@@ -223,6 +223,10 @@
                if (match_op(next, '=')) {
                        struct expression *expr;
                        next = constant_expression(next->next, &expr);
+
+                       if (!evaluate_expression(expr))
+                               error_die(valtok->pos, "enumerator value for 
`%s' not integer constant\n",
+                                         show_ident(token->ident));
                        lastval = get_expression_value(expr);
                        ctype = expr->ctype;
                } else if (!ctype) {



On Tue, Mar 01, 2005 at 03:08:20AM +0200, Alexey Dobriyan wrote:
> Ran sparse on subversion source code. Trimmed down real file to this:
> 
>       enum a {
>               b = c,
>       };
> 
> $ sparse cle.h
> cle.h:2:6: warning: undefined identifier 'c'
> cle.h:2:6: warning: bad constant expression type
> Segmentation fault
> 
>       Alexey
> -
> 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
-
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