From 962e4b1ad3b3cb13c7427d07dfa44cd15af11693 Mon Sep 17 00:00:00 2001
From: Martin Nagy <nagy.martin@gmail.com>
Date: Sat, 25 Apr 2009 12:56:33 +0200
Subject: [PATCH] Print an error if typeof() lacks an argument
We weren't checking if the initializer isn't NULL, which caused sparse
to segfault later on when performing lazy evaluation in classify_type().
Signed-off-by: Martin Nagy <nagy.martin@gmail.com>
---
parse.c | 17 +++++++++++------
1 files changed, 11 insertions(+), 6 deletions(-)
@@ -924,12 +924,17 @@ static struct token *typeof_specifier(struct token *token, struct decl_state *ct
ctx->ctype.base_type = sym->ctype.base_type;
apply_ctype(token->pos, &sym->ctype, &ctx->ctype);
} else {
- struct symbol *typeof_sym = alloc_symbol(token->pos, SYM_TYPEOF);
- token = parse_expression(token->next, &typeof_sym->initializer);
-
- typeof_sym->endpos = token->pos;
- ctx->ctype.base_type = typeof_sym;
- }
+ struct expression *expr;
+ token = parse_expression(token->next, &expr);
+ if (expr) {
+ struct symbol *typeof_sym = alloc_symbol(token->pos, SYM_TYPEOF);
+ typeof_sym->endpos = token->pos;
+ typeof_sym->initializer = expr;
+ ctx->ctype.base_type = typeof_sym;
+ } else {
+ sparse_error(token->pos, "expected expression after the '(' token");
+ }
+ }
return expect(token, ')', "after typeof");
}
--
1.6.0.6