diff options
author | Jan Edmund Lazo <janedmundlazo@hotmail.com> | 2018-07-22 23:50:45 -0400 |
---|---|---|
committer | Jan Edmund Lazo <janedmundlazo@hotmail.com> | 2018-07-23 00:01:07 -0400 |
commit | 9fbbec76aaa8d45ba54bb136b750f2ccc440207f (patch) | |
tree | 1982530ce2646ef8e87a1172e610da77715daa8d | |
parent | c8e7a447c5694e7e2a58f2b112530d896efa30ba (diff) | |
download | rneovim-9fbbec76aaa8d45ba54bb136b750f2ccc440207f.tar.gz rneovim-9fbbec76aaa8d45ba54bb136b750f2ccc440207f.tar.bz2 rneovim-9fbbec76aaa8d45ba54bb136b750f2ccc440207f.zip |
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.
https://github.com/vim/vim/commit/71a43c01377cb0c5cdc5f2d9a357b5ef1aa69ee3
-rw-r--r-- | src/nvim/ex_getln.c | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 775d002e58..fd11acff84 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -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) { - char_u *retstr; - char_u *s; char_u *e; - char_u keep; garray_T ga; - retstr = call_user_expand_func((user_expand_func_T)call_func_retstr, xp, - num_file, file); + char_u *const retstr = call_user_expand_func( + (user_expand_func_T)call_func_retstr, xp, num_file, file); if (retstr == NULL) { return FAIL; } 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'); if (e == NULL) e = s + STRLEN(s); - keep = *e; - *e = 0; + const int keep = *e; + *e = NUL; - if (xp->xp_pattern[0] && vim_regexec(regmatch, s, (colnr_T)0) == 0) { - *e = keep; - if (*e != NUL) - ++e; - continue; + const bool skip = xp->xp_pattern[0] + && vim_regexec(regmatch, s, (colnr_T)0) == 0; + *e = keep; + if (!skip) { + GA_APPEND(char_u *, &ga, vim_strnsave(s, (int)(e - s))); } - GA_APPEND(char_u *, &ga, vim_strnsave(s, (int)(e - s))); - - *e = keep; - if (*e != NUL) - ++e; + if (*e != NUL) { + e++; + } } xfree(retstr); *file = ga.ga_data; |