mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #4096 from justinmk/coverity125476
coverity/125476: RI: Null pointer dereference
This commit is contained in:
commit
73e83e8566
@ -10822,15 +10822,15 @@ static void f_globpath(typval_T *argvars, typval_T *rettv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// "glob2regpat()" function
|
||||||
* "glob2regpat()" function
|
|
||||||
*/
|
|
||||||
static void f_glob2regpat(typval_T *argvars, typval_T *rettv)
|
static void f_glob2regpat(typval_T *argvars, typval_T *rettv)
|
||||||
{
|
{
|
||||||
char_u *pat = get_tv_string_chk(&argvars[0]);
|
char_u *pat = get_tv_string_chk(&argvars[0]); // NULL on type error
|
||||||
|
|
||||||
rettv->v_type = VAR_STRING;
|
rettv->v_type = VAR_STRING;
|
||||||
rettv->vval.v_string = file_pat_to_reg_pat(pat, NULL, NULL, FALSE);
|
rettv->vval.v_string = (pat == NULL)
|
||||||
|
? NULL
|
||||||
|
: file_pat_to_reg_pat(pat, NULL, NULL, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -7106,6 +7106,7 @@ char_u * file_pat_to_reg_pat(
|
|||||||
char *allow_dirs, // Result passed back out in here
|
char *allow_dirs, // Result passed back out in here
|
||||||
int no_bslash // Don't use a backward slash as pathsep
|
int no_bslash // Don't use a backward slash as pathsep
|
||||||
)
|
)
|
||||||
|
FUNC_ATTR_NONNULL_ARG(1)
|
||||||
{
|
{
|
||||||
const char_u *endp;
|
const char_u *endp;
|
||||||
char_u *reg_pat;
|
char_u *reg_pat;
|
||||||
@ -7118,6 +7119,10 @@ char_u * file_pat_to_reg_pat(
|
|||||||
if (pat_end == NULL)
|
if (pat_end == NULL)
|
||||||
pat_end = pat + STRLEN(pat);
|
pat_end = pat + STRLEN(pat);
|
||||||
|
|
||||||
|
if (pat_end == pat) {
|
||||||
|
return (char_u *)xstrdup("^$");
|
||||||
|
}
|
||||||
|
|
||||||
size_t size = 2; // '^' at start, '$' at end.
|
size_t size = 2; // '^' at start, '$' at end.
|
||||||
|
|
||||||
for (p = pat; p < pat_end; p++) {
|
for (p = pat; p < pat_end; p++) {
|
||||||
|
@ -69,6 +69,12 @@ static char *features[] = {
|
|||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
static int included_patches[] = {
|
static int included_patches[] = {
|
||||||
|
1081,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
1055,
|
1055,
|
||||||
// 1054,
|
// 1054,
|
||||||
// 1053,
|
// 1053,
|
||||||
|
22
test/functional/legacy/glob2regpat_spec.lua
Normal file
22
test/functional/legacy/glob2regpat_spec.lua
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
-- Tests for signs
|
||||||
|
|
||||||
|
local helpers = require('test.functional.helpers')
|
||||||
|
local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect
|
||||||
|
local eq, neq, eval = helpers.eq, helpers.neq, helpers.eval
|
||||||
|
|
||||||
|
describe('glob2regpat()', function()
|
||||||
|
before_each(clear)
|
||||||
|
|
||||||
|
it('handles invalid input', function()
|
||||||
|
execute('call glob2regpat(1.33)')
|
||||||
|
helpers.feed('<cr>')
|
||||||
|
neq(nil, string.find(eval('v:errmsg'), '^E806:'))
|
||||||
|
end)
|
||||||
|
it('returns ^$ for empty input', function()
|
||||||
|
eq('^$', eval("glob2regpat('')"))
|
||||||
|
end)
|
||||||
|
it('handles valid input', function()
|
||||||
|
eq('^foo\\.', eval("glob2regpat('foo.*')"))
|
||||||
|
eq('\\.vim$', eval("glob2regpat('*.vim')"))
|
||||||
|
end)
|
||||||
|
end)
|
Loading…
Reference in New Issue
Block a user