From e23238ea0e0280f2823cc9ecd10f965c094a71b0 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 1 Nov 2012 11:43:17 +0300 Subject: [PATCH] check_precedence: fix a segfault This test should have been OK, but apparently there is a way to try make this parse an expression struct which wasn't been initialized all the way. What happened here is that I had a VALUE expression with the ->op set to '!'. In some ways, this fix is a hack, but in another way it is just making the check more robust. Here is the example program with triggered the bug. enum { OST_FALSE = 0, OST_TRUE = (!OST_FALSE) }; int test(void) { int x = 0; if (OST_TRUE == x) { } } Reported-by: Pontus Fuchs Signed-off-by: Dan Carpenter --- check_precedence.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_precedence.c b/check_precedence.c index 8c1ce5d7..7ad719f9 100644 --- a/check_precedence.c +++ b/check_precedence.c @@ -54,7 +54,7 @@ static void match_condition(struct expression *expr) if (expr->type == EXPR_COMPARE) { if (expr->left->type == EXPR_COMPARE || expr->right->type == EXPR_COMPARE) print = 1; - if (expr->left->op == '!') { + if (expr->left->type == EXPR_PREOP && expr->left->op == '!') { if (expr->left->type == EXPR_PREOP && expr->left->unop->op == '!') return; if (expr->right->op == '!') -- 2.11.4.GIT