# HG changeset patch # User Bram Moolenaar # Date 1598896805 -7200 # Node ID 468569085ab28ef695206925f3cb834ca2bcc999 # Parent ea3ef673c28f573e646b6fc4634e645b3b862443 patch 8.2.1552: warnings from asan with clang-11 Commit: https://github.com/vim/vim/commit/64f37d309025a65210dbc33823ec9ec5d547775f Author: Bram Moolenaar Date: Mon Aug 31 19:58:13 2020 +0200 patch 8.2.1552: warnings from asan with clang-11 Problem: Warnings from asan with clang-11. (James McCoy) Solution: Avoid using a NULL pointer. (issue https://github.com/vim/vim/issues/6811) diff --git a/src/fold.c b/src/fold.c --- a/src/fold.c +++ b/src/fold.c @@ -820,13 +820,16 @@ foldUpdate(win_T *wp, linenr_T top, line 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, f 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, 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) diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -755,6 +755,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1552, +/**/ 1551, /**/ 1550,