fix(api): vim.cmd.make crashes when argument count isn't 1 (#19701)

Closes #19696
This commit is contained in:
Famiu Haque
2022-08-10 16:37:59 +06:00
committed by GitHub
parent 3ee6c05b4b
commit 78658ef383
2 changed files with 12 additions and 2 deletions

View File

@@ -819,10 +819,13 @@ static void build_cmdline_str(char **cmdlinep, exarg_T *eap, CmdParseInfo *cmdin
char *p = replace_makeprg(eap, eap->arg, cmdlinep); char *p = replace_makeprg(eap, eap->arg, cmdlinep);
if (p != eap->arg) { if (p != eap->arg) {
// If replace_makeprg modified the cmdline string, correct the argument pointers. // If replace_makeprg modified the cmdline string, correct the argument pointers.
assert(argc == 1);
eap->arg = p; eap->arg = p;
// We can only know the position of the first argument because the argument list can be used
// multiple times in makeprg / grepprg.
if (argc >= 1) {
eap->args[0] = p; eap->args[0] = p;
} }
}
} }
/// Create a new user command |user-commands| /// Create a new user command |user-commands|

View File

@@ -3829,5 +3829,12 @@ describe('API', function()
eq({'aa'}, meths.buf_get_lines(0, 0, 1, false)) eq({'aa'}, meths.buf_get_lines(0, 0, 1, false))
assert_alive() assert_alive()
end) end)
it("'make' command works when argument count isn't 1 #19696", function()
command('set makeprg=echo')
meths.cmd({ cmd = 'make' }, {})
assert_alive()
meths.cmd({ cmd = 'make', args = { 'foo', 'bar' } }, {})
assert_alive()
end)
end) end)
end) end)