Skip to contentSkip to conversation

Set *tree to NULL on error

PATCH New Vegard Nossum 1 participant 1 message May 25, 2008 Sparse checker

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Set *tree to NULL on error

From: Vegard Nossum <[email protected]>
Date: Sun, 25 May 2008 10:29:19 +0200
Subject: [PATCH] Set *tree to NULL on error

On "Syntax error in unary expression", the output parameter "tree" would be left uninitialized and subsequently used in unary_expression(), leading to segfault.

Caught by valgrind and fixed by me ;-)

---
 expression.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
expression.c +2 -0
index 289927a..f634b07 100644
@@ -654,6 +654,7 @@ static struct token *unary_expression(struct token *token, struct expression **t
 			next = cast_expression(token->next, &unop);
 			if (!unop) {
 				sparse_error(token->pos, "Syntax error in unary expression");
+				*tree = NULL;
 				return next;
 			}
 			unary = alloc_expression(token->pos, EXPR_PREOP);
@@ -671,6 +672,7 @@ static struct token *unary_expression(struct token *token, struct expression **t
 			next = cast_expression(token->next, &unop);
 			if (!unop) {
 				sparse_error(token->pos, "Syntax error in unary expression");
+				*tree = NULL;
 				return next;
 			}
 			unary = alloc_expression(token->pos, EXPR_PREOP);
Signature · 1 line
1.5.4.1