vim-patch:8.0.1502: in out-of-memory situation character is not restored

Problem:    In out-of-memory situation character is not restored. (Coverity)
Solution:   Restore the character in all situations.
71a43c0137
This commit is contained in:
Jan Edmund Lazo 2018-07-22 23:50:45 -04:00
parent c8e7a447c5
commit 9fbbec76aa

View File

@ -5062,38 +5062,33 @@ static void * call_user_expand_func(user_expand_func_T user_expand_func,
*/ */
static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file) static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file)
{ {
char_u *retstr;
char_u *s;
char_u *e; char_u *e;
char_u keep;
garray_T ga; garray_T ga;
retstr = call_user_expand_func((user_expand_func_T)call_func_retstr, xp, char_u *const retstr = call_user_expand_func(
num_file, file); (user_expand_func_T)call_func_retstr, xp, num_file, file);
if (retstr == NULL) { if (retstr == NULL) {
return FAIL; return FAIL;
} }
ga_init(&ga, (int)sizeof(char *), 3); ga_init(&ga, (int)sizeof(char *), 3);
for (s = retstr; *s != NUL; s = e) { for (char_u *s = retstr; *s != NUL; s = e) {
e = vim_strchr(s, '\n'); e = vim_strchr(s, '\n');
if (e == NULL) if (e == NULL)
e = s + STRLEN(s); e = s + STRLEN(s);
keep = *e; const int keep = *e;
*e = 0; *e = NUL;
if (xp->xp_pattern[0] && vim_regexec(regmatch, s, (colnr_T)0) == 0) { const bool skip = xp->xp_pattern[0]
*e = keep; && vim_regexec(regmatch, s, (colnr_T)0) == 0;
if (*e != NUL) *e = keep;
++e; if (!skip) {
continue; GA_APPEND(char_u *, &ga, vim_strnsave(s, (int)(e - s)));
} }
GA_APPEND(char_u *, &ga, vim_strnsave(s, (int)(e - s))); if (*e != NUL) {
e++;
*e = keep; }
if (*e != NUL)
++e;
} }
xfree(retstr); xfree(retstr);
*file = ga.ga_data; *file = ga.ga_data;