aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
-rw-r--r--parse.c6
-rw-r--r--validation/bad-typeof.c14
2 files changed, 19 insertions, 1 deletions
diff --git a/parse.c b/parse.c
index 96621229..e7dbeb9c 100644
--- a/parse.c
+++ b/parse.c
@@ -928,8 +928,12 @@ static struct token *typeof_specifier(struct token *token, struct decl_state *ct
token = parse_expression(token->next, &typeof_sym->initializer);
typeof_sym->endpos = token->pos;
+ if (!typeof_sym->initializer) {
+ sparse_error(token->pos, "expected expression after the '(' token");
+ typeof_sym = &bad_ctype;
+ }
ctx->ctype.base_type = typeof_sym;
- }
+ }
return expect(token, ')', "after typeof");
}
diff --git a/validation/bad-typeof.c b/validation/bad-typeof.c
new file mode 100644
index 00000000..90c3e424
--- /dev/null
+++ b/validation/bad-typeof.c
@@ -0,0 +1,14 @@
+static int fun(void)
+{
+ typeof() a;
+ int b;
+
+ a = b;
+}
+/*
+ * check-name: Bad typeof syntax segfault
+ *
+ * check-error-start
+bad-typeof.c:3:16: error: expected expression after the '(' token
+ * check-error-end
+ */