]> granicus.if.org Git - vim/commitdiff
patch 8.2.1552: warnings from asan with clang-11 v8.2.1552
authorBram Moolenaar <Bram@vim.org>
Mon, 31 Aug 2020 17:58:13 +0000 (19:58 +0200)
committerBram Moolenaar <Bram@vim.org>
Mon, 31 Aug 2020 17:58:13 +0000 (19:58 +0200)
Problem:    Warnings from asan with clang-11. (James McCoy)
Solution:   Avoid using a NULL pointer. (issue #6811)

src/fold.c
src/version.c

index 043037fa64e5c71070e2d966aee72e18a7afec70..e4ae9cbc0b363924747f0680c83da38275c1432b 100644 (file)
@@ -820,13 +820,16 @@ foldUpdate(win_T *wp, linenr_T top, linenr_T bot)
        return;
 #endif
 
-    // Mark all folds from top to bot as maybe-small.
-    (void)foldFind(&wp->w_folds, top, &fp);
-    while (fp < (fold_T *)wp->w_folds.ga_data + wp->w_folds.ga_len
-           && fp->fd_top < bot)
+    if (wp->w_folds.ga_len > 0)
     {
-       fp->fd_small = MAYBE;
-       ++fp;
+       // Mark all folds from top to bot as maybe-small.
+       (void)foldFind(&wp->w_folds, top, &fp);
+       while (fp < (fold_T *)wp->w_folds.ga_data + wp->w_folds.ga_len
+               && fp->fd_top < bot)
+       {
+           fp->fd_small = MAYBE;
+           ++fp;
+       }
     }
 
     if (foldmethodIsIndent(wp)
@@ -1127,6 +1130,12 @@ foldFind(garray_T *gap, linenr_T lnum, fold_T **fpp)
     fold_T     *fp;
     int                i;
 
+    if (gap->ga_len == 0)
+    {
+       *fpp = NULL;
+       return FALSE;
+    }
+
     /*
      * Perform a binary search.
      * "low" is lowest index of possible match.
@@ -2500,14 +2509,14 @@ foldUpdateIEMSRecurse(
                // Find an existing fold to re-use.  Preferably one that
                // includes startlnum, otherwise one that ends just before
                // startlnum or starts after it.
-               if (foldFind(gap, startlnum, &fp)
+               if (gap->ga_len > 0 && (foldFind(gap, startlnum, &fp)
                        || (fp < ((fold_T *)gap->ga_data) + gap->ga_len
                            && fp->fd_top <= firstlnum)
                        || foldFind(gap, firstlnum - concat, &fp)
                        || (fp < ((fold_T *)gap->ga_data) + gap->ga_len
                            && ((lvl < level && fp->fd_top < flp->lnum)
                                || (lvl >= level
-                                          && fp->fd_top <= flp->lnum_save))))
+                                          && fp->fd_top <= flp->lnum_save)))))
                {
                    if (fp->fd_top + fp->fd_len + concat > firstlnum)
                    {
@@ -2622,7 +2631,10 @@ foldUpdateIEMSRecurse(
                {
                    // Insert new fold.  Careful: ga_data may be NULL and it
                    // may change!
-                   i = (int)(fp - (fold_T *)gap->ga_data);
+                   if (gap->ga_len == 0)
+                       i = 0;
+                   else
+                       i = (int)(fp - (fold_T *)gap->ga_data);
                    if (foldInsert(gap, i) != OK)
                        return bot;
                    fp = (fold_T *)gap->ga_data + i;
@@ -2841,7 +2853,7 @@ foldInsert(garray_T *gap, int i)
     if (ga_grow(gap, 1) != OK)
        return FAIL;
     fp = (fold_T *)gap->ga_data + i;
-    if (i < gap->ga_len)
+    if (gap->ga_len > 0 && i < gap->ga_len)
        mch_memmove(fp + 1, fp, sizeof(fold_T) * (gap->ga_len - i));
     ++gap->ga_len;
     ga_init2(&fp->fd_nested, (int)sizeof(fold_T), 10);
@@ -2928,7 +2940,7 @@ foldRemove(garray_T *gap, linenr_T top, linenr_T bot)
     if (bot < top)
        return;         // nothing to do
 
-    for (;;)
+    while (gap->ga_len > 0)
     {
        // Find fold that includes top or a following one.
        if (foldFind(gap, top, &fp) && fp->fd_top < top)
index 901f54086180eb85a7c3b9b7ece9dff8595aed09..b709939f6aa49f19584b4806db352202c67134cc 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1552,
 /**/
     1551,
 /**/