harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit f74e171d7d9b9d40e53d996b0bf4388bdb6a3f5f
parent c4d2d1d69a6031362b09ce62a2c9c8112c839438
Author: Armin Weigl <tb46305@gmail.com>
Date:   Wed, 24 Feb 2021 17:44:38 +0100

fix segfault on import of nonexistant member

Diffstat:
Msrc/check.c | 3+++
Msrc/parse.c | 11+++++++++++
2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/src/check.c b/src/check.c @@ -2639,6 +2639,9 @@ load_import(struct ast_imports *import, .ns = &import->ident, }; const struct scope_object *obj = scope_lookup(mod, &ident); + char buf[1024]; + identifier_unparse_static(&ident, buf, sizeof(buf)); + expect(&member->loc, obj, "Unknown object '%s'", buf); scope_insert(scope, obj->otype, &obj->ident, &name, obj->type, obj->value); if (type_dealias(obj->type)->storage != STORAGE_ENUM diff --git a/src/parse.c b/src/parse.c @@ -62,6 +62,16 @@ want(struct lexer *lexer, enum lexical_token ltok, struct token *tok) token_finish(out); } } +static struct location +locdup(const struct location *loc) +{ + struct location new_loc = { + .lineno = loc->lineno, + .colno = loc->colno, + .path = strdup(loc->path), + }; + return new_loc; +} static struct ast_expression * mkexpr(const struct location *loc) @@ -148,6 +158,7 @@ parse_name_list(struct lexer *lexer, struct ast_imports *name) struct token tok = {0}; want(lexer, T_NAME, &tok); name->ident.name = strdup(tok.name); + name->loc = locdup(&tok.loc); token_finish(&tok); switch (lex(lexer, &tok)) {