Skip to content

Commit

Permalink
patch 8.2.1552: warnings from asan with clang-11
Browse files Browse the repository at this point in the history
Problem:    Warnings from asan with clang-11. (James McCoy)
Solution:   Avoid using a NULL pointer. (issue #6811)
  • Loading branch information
brammool committed Aug 31, 2020
1 parent 8b565c2 commit 64f37d3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/fold.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1552,
/**/
1551,
/**/
Expand Down

0 comments on commit 64f37d3

Please sign in to comment.