From 3ca4d91b96f774832e131ead8099ea6080275122 Mon Sep 17 00:00:00 2001 From: Martin Vogel Date: Tue, 3 Nov 2026 03:08:35 +0100 Subject: [PATCH] fix(go): a definition with no name is no definition, not the key 12:(null) GCC's production build refused the null %s, with -Werror. Also the Lua and Shell adapters' cppcheck items: an always-false check and three scopes that can narrow. Signed-off-by: Martin Vogel --- internal/cbm/lsp/go_stabilize.c | 6 ++++-- internal/cbm/resolve/adapter_lua.c | 14 ++++++++------ internal/cbm/resolve/adapter_shell.c | 5 +++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/internal/cbm/lsp/go_stabilize.c b/internal/cbm/lsp/go_stabilize.c index ec1f99c1c..21ce143f8 100644 --- a/internal/cbm/lsp/go_stabilize.c +++ b/internal/cbm/lsp/go_stabilize.c @@ -1486,8 +1486,10 @@ static void member_domains(go_collect_t *c, TSNode node, const char *name, const } static const CBMDefinition *definition(go_collect_t *c, TSNode node, TSNode name) { - const char *key = cbm_arena_sprintf(&c->call_arena, "%u:%s", ts_node_start_point(node).row + 1, - text(c, name)); + const char *spelled = text(c, name); + const char *key = spelled ? cbm_arena_sprintf(&c->call_arena, "%u:%s", + ts_node_start_point(node).row + 1, spelled) + : NULL; const void *value = key ? cbm_ht_get(c->definitions, key) : NULL; return value == c ? NULL : value; } diff --git a/internal/cbm/resolve/adapter_lua.c b/internal/cbm/resolve/adapter_lua.c index de582a7bd..5b69db35a 100644 --- a/internal/cbm/resolve/adapter_lua.c +++ b/internal/cbm/resolve/adapter_lua.c @@ -830,10 +830,12 @@ static lua_value_t lua_eval_uncached(lua_ctx_t *ctx, const char *encoded, unsign lua_value_t value = lua_eval_root(ctx, root, depth); while (step) { const char *next = strchr(step + 1, LUA_STEP[0]); - const char *part = - next ? cbm_arena_strndup(walk->arena, step + 1, (size_t)(next - step - 1)) : step + 1; - if (!part) - return lua_unknown("lua_value_allocation"); + const char *part = step + 1; + if (next) { + part = cbm_arena_strndup(walk->arena, step + 1, (size_t)(next - step - 1)); + if (!part) + return lua_unknown("lua_value_allocation"); + } value = part[0] == '.' ? lua_member(ctx, value, part + 1, depth) : part[0] == '#' ? lua_call_value_at(ctx, value, part + 1, depth) : lua_call_result(ctx, value, depth); @@ -1525,9 +1527,9 @@ static void lua_visit_table(lua_ctx_t *ctx, TSNode node, unsigned depth) { cbm_source_walk_t *walk = ctx->walk; const char *owner = ctx->collecting ? lua_identity(ctx, 'T', ts_node_start_byte(node)) : NULL; const char *pending = NULL; - uint32_t pending_row = 0; TSTreeCursor cursor = ts_tree_cursor_new(node); if (ts_tree_cursor_goto_first_child(&cursor)) { + uint32_t pending_row = 0; do { TSNode field = ts_tree_cursor_current_node(&cursor); if (cbm_source_is(field, "comment")) { @@ -1784,9 +1786,9 @@ static void lua_visit_statements(lua_ctx_t *ctx, TSNode node, unsigned depth) { /* `local` and `global` are field names on the statement, not kinds. */ lua_doc_t doc = {0}; lua_doc_t *outer = ctx->doc; - uint32_t last_row = UINT32_MAX; TSTreeCursor cursor = ts_tree_cursor_new(node); if (ts_tree_cursor_goto_first_child(&cursor)) { + uint32_t last_row = UINT32_MAX; do { TSNode child = ts_tree_cursor_current_node(&cursor); if (!ts_node_is_named(child)) diff --git a/internal/cbm/resolve/adapter_shell.c b/internal/cbm/resolve/adapter_shell.c index 443dcd5d8..1df30cc33 100644 --- a/internal/cbm/resolve/adapter_shell.c +++ b/internal/cbm/resolve/adapter_shell.c @@ -215,12 +215,13 @@ static void shell_collect_walk(shell_ctx_t *ctx, TSNode node, unsigned depth) { return; if (cbm_source_is(node, "function_definition")) { const char *name = cbm_source_text(walk, cbm_source_field(node, "name")); - uint32_t line = ts_node_start_point(node).row + 1; const cbm_source_decl_t *first = name ? cbm_source_lookup(walk, ctx->functions, name) : NULL; - if (name && !first) + if (name && !first) { + uint32_t line = ts_node_start_point(node).row + 1; (void)cbm_source_declare(walk, ctx->functions, name, cbm_source_def_qn_at(walk, name, line), 0, line); + } } else if (cbm_source_is(node, "command")) { const char *word = shell_command_word(walk, node); if (word && (!strcmp(word, "source") || !strcmp(word, ".")))