diff options
Diffstat (limited to 'src/nvim/lua/executor.c')
-rw-r--r-- | src/nvim/lua/executor.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index bac6f4ca9a..c29e670c33 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -1928,7 +1928,7 @@ static garray_T expand_result_array = GA_EMPTY_INIT_VALUE; /// Finds matches for Lua cmdline completion and advances xp->xp_pattern after prefix. /// This should be called before xp->xp_pattern is first used. -void nlua_expand_pat(expand_T *xp, const char *pat) +void nlua_expand_pat(expand_T *xp) { lua_State *const lstate = global_lstate; int status = FAIL; @@ -1941,7 +1941,10 @@ void nlua_expand_pat(expand_T *xp, const char *pat) luaL_checktype(lstate, -1, LUA_TFUNCTION); // [ vim, vim._expand_pat, pat ] - lua_pushstring(lstate, pat); + const char *pat = xp->xp_pattern; + assert(xp->xp_line + xp->xp_col >= pat); + ptrdiff_t patlen = xp->xp_line + xp->xp_col - pat; + lua_pushlstring(lstate, pat, (size_t)patlen); if (nlua_pcall(lstate, 1, 2) != 0) { nlua_error(lstate, _("Error executing vim._expand_pat: %.*s")); @@ -1951,8 +1954,8 @@ void nlua_expand_pat(expand_T *xp, const char *pat) Error err = ERROR_INIT; Arena arena = ARENA_EMPTY; - int prefix_len = (int)nlua_pop_Integer(lstate, &arena, &err); - if (ERROR_SET(&err)) { + ptrdiff_t prefix_len = nlua_pop_Integer(lstate, &arena, &err); + if (ERROR_SET(&err) || prefix_len > patlen) { goto cleanup; } |