fix: assert failure in VimL expression parser

This commit is contained in:
Rustum Zia
2024-07-10 17:42:37 -04:00
parent 167d0e5a6c
commit 6720bd440f
2 changed files with 7 additions and 9 deletions

View File

@ -1264,21 +1264,12 @@ static bool viml_pexpr_handle_bop(const ParserState *const pstate, ExprASTStack
|| bop_node->type == kExprNodeSubscript)
? kEOpLvlSubscript
: node_lvl(*bop_node));
#ifndef NDEBUG
const ExprOpAssociativity bop_node_ass = (
(bop_node->type == kExprNodeCall
|| bop_node->type == kExprNodeSubscript)
? kEOpAssLeft
: node_ass(*bop_node));
#endif
do {
ExprASTNode **new_top_node_p = kv_last(*ast_stack);
ExprASTNode *new_top_node = *new_top_node_p;
assert(new_top_node != NULL);
const ExprOpLvl new_top_node_lvl = node_lvl(*new_top_node);
const ExprOpAssociativity new_top_node_ass = node_ass(*new_top_node);
assert(bop_node_lvl != new_top_node_lvl
|| bop_node_ass == new_top_node_ass);
if (top_node_p != NULL
&& ((bop_node_lvl > new_top_node_lvl
|| (bop_node_lvl == new_top_node_lvl

View File

@ -2938,6 +2938,13 @@ describe('API', function()
return ('%s(%s)%s'):format(typ, args, rest)
end
end
it('does not crash parsing invalid VimL expression #29648', function()
api.nvim_input(':<C-r>=')
api.nvim_input('1bork/')
assert_alive()
end)
require('test.unit.viml.expressions.parser_tests')(it, _check_parsing, hl, fmtn)
end)