vim-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 vim/vim#6811)
64f37d3090
This commit is contained in:
James McCoy 2020-09-03 22:55:20 -04:00
parent 3acfefb63e
commit 0c851e5226
No known key found for this signature in database
GPG Key ID: DFE691AE331BA3DB

View File

@ -788,13 +788,15 @@ void foldUpdate(win_T *wp, linenr_T top, linenr_T bot)
return;
}
// Mark all folds from top to bot as maybe-small.
fold_T *fp;
(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 = kNone;
fp++;
if (wp->w_folds.ga_len > 0) {
// Mark all folds from top to bot as maybe-small.
fold_T *fp;
(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 = kNone;
fp++;
}
}
if (foldmethodIsIndent(wp)
@ -1063,6 +1065,11 @@ static int foldFind(const garray_T *gap, linenr_T lnum, fold_T **fpp)
linenr_T low, high;
fold_T *fp;
if (gap->ga_len == 0) {
*fpp = NULL;
return FALSE;
}
/*
* Perform a binary search.
* "low" is lowest index of possible match.
@ -2269,14 +2276,14 @@ static linenr_T 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) {
/* Use existing fold for the new fold. If it starts
* before where we started looking, extend it. If it
@ -2367,7 +2374,11 @@ static linenr_T foldUpdateIEMSRecurse(
} else {
/* 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);
}
foldInsert(gap, i);
fp = (fold_T *)gap->ga_data + i;
/* The new fold continues until bot, unless we find the
@ -2563,7 +2574,7 @@ static void foldInsert(garray_T *gap, int i)
ga_grow(gap, 1);
fp = (fold_T *)gap->ga_data + i;
if (i < gap->ga_len)
if (gap->ga_len > 0 && i < gap->ga_len)
memmove(fp + 1, fp, sizeof(fold_T) * (size_t)(gap->ga_len - i));
++gap->ga_len;
ga_init(&fp->fd_nested, (int)sizeof(fold_T), 10);
@ -2645,7 +2656,7 @@ static void foldRemove(
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) {
// 2: or 3: need to delete nested folds