fix(treesitter): treecursor regression

- Also address some coverity warnings

Fixes #27942
This commit is contained in:
Lewis Russell
2024-03-20 09:35:29 +00:00
committed by Lewis Russell
parent 9765efb40f
commit 0f85aeb478

View File

@ -144,6 +144,7 @@ static TSLanguage *lang_check(lua_State *L, int index)
TSLanguage *lang = pmap_get(cstr_t)(&langs, lang_name); TSLanguage *lang = pmap_get(cstr_t)(&langs, lang_name);
if (!lang) { if (!lang) {
luaL_error(L, "no such language: %s", lang_name); luaL_error(L, "no such language: %s", lang_name);
return NULL; // Coverity doesn't know luaL_error is noreturn
} }
return lang; return lang;
} }
@ -230,6 +231,7 @@ static TSParser *parser_check(lua_State *L, uint16_t index)
TSParser **ud = luaL_checkudata(L, index, TS_META_PARSER); TSParser **ud = luaL_checkudata(L, index, TS_META_PARSER);
if (!ud || !(*ud)) { if (!ud || !(*ud)) {
luaL_argerror(L, index, "TSParser expected"); luaL_argerror(L, index, "TSParser expected");
return NULL; // Coverity doesn't know luaL_error is noreturn
} }
return *ud; return *ud;
} }
@ -633,6 +635,7 @@ static TSLuaTree *tree_check(lua_State *L, int index)
TSLuaTree *ud = luaL_checkudata(L, index, TS_META_TREE); TSLuaTree *ud = luaL_checkudata(L, index, TS_META_TREE);
if (!ud) { if (!ud) {
luaL_argerror(L, index, "TSTree expected"); luaL_argerror(L, index, "TSTree expected");
return NULL; // Coverity doesn't know luaL_error is noreturn
} }
return ud; return ud;
} }
@ -715,9 +718,10 @@ static struct luaL_Reg treecursor_meta[] = {
static TSTreeCursor *treecursor_check(lua_State *L, int index) static TSTreeCursor *treecursor_check(lua_State *L, int index)
{ {
TSTreeCursor *ud = luaL_checkudata(L, lua_upvalueindex(1), TS_META_TREECURSOR); TSTreeCursor *ud = luaL_checkudata(L, index, TS_META_TREECURSOR);
if (!ud) { if (!ud) {
luaL_error(L, "TSTreeCursor expected"); luaL_error(L, "TSTreeCursor expected");
return NULL; // Coverity doesn't know luaL_error is noreturn
} }
return ud; return ud;
} }
@ -805,6 +809,7 @@ static TSNode node_check(lua_State *L, int index)
TSNode *ud = luaL_checkudata(L, index, TS_META_NODE); TSNode *ud = luaL_checkudata(L, index, TS_META_NODE);
if (!ud) { if (!ud) {
luaL_argerror(L, index, "TSNode expected"); luaL_argerror(L, index, "TSNode expected");
abort(); // Coverity doesn't know luaL_error is noreturn
} }
return *ud; return *ud;
} }
@ -1044,23 +1049,21 @@ static int node_next_child(lua_State *L)
} }
} }
if (ts_tree_cursor_goto_next_sibling(cursor)) { if (!ts_tree_cursor_goto_next_sibling(cursor)) {
push: return 0;
push_node(L,
ts_tree_cursor_current_node(cursor),
lua_upvalueindex(2)); // [node]
const char *field = ts_tree_cursor_current_field_name(cursor);
if (field != NULL) {
lua_pushstring(L, ts_tree_cursor_current_field_name(cursor));
} else {
lua_pushnil(L);
} // [node, field_name_or_nil]
return 2;
} }
return 0; push:
push_node(L, ts_tree_cursor_current_node(cursor), lua_upvalueindex(2)); // [node]
const char *field = ts_tree_cursor_current_field_name(cursor);
if (field != NULL) {
lua_pushstring(L, ts_tree_cursor_current_field_name(cursor));
} else {
lua_pushnil(L);
} // [node, field_name_or_nil]
return 2;
} }
static int node_iter_children(lua_State *L) static int node_iter_children(lua_State *L)
@ -1277,6 +1280,7 @@ static TSQueryCursor *querycursor_check(lua_State *L, int index)
TSQueryCursor **ud = luaL_checkudata(L, index, TS_META_QUERYCURSOR); TSQueryCursor **ud = luaL_checkudata(L, index, TS_META_QUERYCURSOR);
if (!ud || !(*ud)) { if (!ud || !(*ud)) {
luaL_argerror(L, index, "TSQueryCursor expected"); luaL_argerror(L, index, "TSQueryCursor expected");
return NULL; // Coverity doesn't know luaL_error is noreturn
} }
return *ud; return *ud;
} }
@ -1310,9 +1314,10 @@ static void push_querymatch(lua_State *L, TSQueryMatch *match, int uindex)
static TSQueryMatch *querymatch_check(lua_State *L, int index) static TSQueryMatch *querymatch_check(lua_State *L, int index)
{ {
TSQueryMatch *ud = luaL_checkudata(L, 1, TS_META_QUERYMATCH); TSQueryMatch *ud = luaL_checkudata(L, index, TS_META_QUERYMATCH);
if (!ud) { if (!ud) {
luaL_argerror(L, index, "TSQueryMatch expected"); luaL_argerror(L, index, "TSQueryMatch expected");
return NULL; // Coverity doesn't know luaL_error is noreturn
} }
return ud; return ud;
} }
@ -1460,6 +1465,7 @@ static TSQuery *query_check(lua_State *L, int index)
TSQuery **ud = luaL_checkudata(L, index, TS_META_QUERY); TSQuery **ud = luaL_checkudata(L, index, TS_META_QUERY);
if (!ud || !(*ud)) { if (!ud || !(*ud)) {
luaL_argerror(L, index, "TSQuery expected"); luaL_argerror(L, index, "TSQuery expected");
return NULL; // Coverity doesn't know luaL_error is noreturn
} }
return *ud; return *ud;
} }