Patch 8.2.1552
Problem:    Warnings from asan with clang-11. (James McCoy)
Solution:   Avoid using a NULL pointer. (issue #6811)
Files:      src/fold.c


*** ../vim-8.2.1551/src/fold.c  2020-06-24 20:33:59.565106319 +0200
--- src/fold.c  2020-08-31 19:54:06.777071471 +0200
***************
*** 820,832 ****
        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)
      {
!       fp->fd_small = MAYBE;
!       ++fp;
      }
  
      if (foldmethodIsIndent(wp)
--- 820,835 ----
        return;
  #endif
  
!     if (wp->w_folds.ga_len > 0)
      {
!       // 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,1132 ****
--- 1130,1141 ----
      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,2513 ****
                // 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)
                        || (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))))
                {
                    if (fp->fd_top + fp->fd_len + concat > firstlnum)
                    {
--- 2509,2522 ----
                // Find an existing fold to re-use.  Preferably one that
                // includes startlnum, otherwise one that ends just before
                // startlnum or starts after it.
!               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)))))
                {
                    if (fp->fd_top + fp->fd_len + concat > firstlnum)
                    {
***************
*** 2622,2628 ****
                {
                    // Insert new fold.  Careful: ga_data may be NULL and it
                    // may change!
!                   i = (int)(fp - (fold_T *)gap->ga_data);
                    if (foldInsert(gap, i) != OK)
                        return bot;
                    fp = (fold_T *)gap->ga_data + i;
--- 2631,2640 ----
                {
                    // Insert new fold.  Careful: ga_data may be NULL and it
                    // may change!
!                   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,2847 ****
      if (ga_grow(gap, 1) != OK)
        return FAIL;
      fp = (fold_T *)gap->ga_data + i;
!     if (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);
--- 2853,2859 ----
      if (ga_grow(gap, 1) != OK)
        return FAIL;
      fp = (fold_T *)gap->ga_data + i;
!     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,2934 ****
      if (bot < top)
        return;         // nothing to do
  
!     for (;;)
      {
        // Find fold that includes top or a following one.
        if (foldFind(gap, top, &fp) && fp->fd_top < top)
--- 2940,2946 ----
      if (bot < top)
        return;         // nothing to do
  
!     while (gap->ga_len > 0)
      {
        // Find fold that includes top or a following one.
        if (foldFind(gap, top, &fp) && fp->fd_top < top)
*** ../vim-8.2.1551/src/version.c       2020-08-30 23:24:17.223401357 +0200
--- src/version.c       2020-08-31 19:57:03.840583615 +0200
***************
*** 756,757 ****
--- 756,759 ----
  {   /* Add new patch number below this line */
+ /**/
+     1552,
  /**/

-- 
Not too long ago, unzipping in public was illegal...

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202008311758.07VHwgwS3111859%40masaka.moolenaar.net.

Raspunde prin e-mail lui