Merge pull request #4096 from justinmk/coverity125476

coverity/125476: RI: Null pointer dereference
This commit is contained in:
Justin M. Keyes 2016-01-28 17:00:49 -05:00
commit 73e83e8566
4 changed files with 39 additions and 6 deletions

View File

@ -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)
{
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->vval.v_string = file_pat_to_reg_pat(pat, NULL, NULL, FALSE);
rettv->v_type = VAR_STRING;
rettv->vval.v_string = (pat == NULL)
? NULL
: file_pat_to_reg_pat(pat, NULL, NULL, false);
}
/*

View File

@ -7106,6 +7106,7 @@ char_u * file_pat_to_reg_pat(
char *allow_dirs, // Result passed back out in here
int no_bslash // Don't use a backward slash as pathsep
)
FUNC_ATTR_NONNULL_ARG(1)
{
const char_u *endp;
char_u *reg_pat;
@ -7118,6 +7119,10 @@ char_u * file_pat_to_reg_pat(
if (pat_end == NULL)
pat_end = pat + STRLEN(pat);
if (pat_end == pat) {
return (char_u *)xstrdup("^$");
}
size_t size = 2; // '^' at start, '$' at end.
for (p = pat; p < pat_end; p++) {

View File

@ -69,6 +69,12 @@ static char *features[] = {
// clang-format off
static int included_patches[] = {
1081,
1055,
// 1054,
// 1053,

View 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)