patch 8.0.1502: in out-of-memory situation character is not restored v8.0.1502
authorBram Moolenaar <Bram@vim.org>
Sun, 11 Feb 2018 14:20:20 +0000 (15:20 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 11 Feb 2018 14:20:20 +0000 (15:20 +0100)
Problem:    In out-of-memory situation character is not restored. (Coverity)
Solution:   Restore the character in all situations.

src/ex_getln.c
src/version.c

index a9d6bd4833c24d8cf2a188553ae33351da84da0d..f92f1dfedd43dd545ac027de125df8f92527e34c 100644 (file)
@@ -5315,8 +5315,9 @@ ExpandUserDefined(
     char_u     *retstr;
     char_u     *s;
     char_u     *e;
-    char_u      keep;
+    int                keep;
     garray_T   ga;
+    int                skip;
 
     retstr = call_user_expand_func(call_func_retstr, xp, num_file, file);
     if (retstr == NULL)
@@ -5329,23 +5330,19 @@ ExpandUserDefined(
        if (e == NULL)
            e = s + STRLEN(s);
        keep = *e;
-       *e = 0;
+       *e = NUL;
 
-       if (xp->xp_pattern[0] && vim_regexec(regmatch, s, (colnr_T)0) == 0)
+       skip = xp->xp_pattern[0] && vim_regexec(regmatch, s, (colnr_T)0) == 0;
+       *e = keep;
+
+       if (!skip)
        {
-           *e = keep;
-           if (*e != NUL)
-               ++e;
-           continue;
+           if (ga_grow(&ga, 1) == FAIL)
+               break;
+           ((char_u **)ga.ga_data)[ga.ga_len] = vim_strnsave(s, (int)(e - s));
+           ++ga.ga_len;
        }
 
-       if (ga_grow(&ga, 1) == FAIL)
-           break;
-
-       ((char_u **)ga.ga_data)[ga.ga_len] = vim_strnsave(s, (int)(e - s));
-       ++ga.ga_len;
-
-       *e = keep;
        if (*e != NUL)
            ++e;
     }
index d96f896ee93608f7a9a65faa8b4a7e288215d45e..62fd9edce90d69ef97ce9398ebe6c29f4dde9b00 100644 (file)
@@ -771,6 +771,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1502,
 /**/
     1501,
 /**/