summaryrefslogtreecommitdiffstats
path: root/src/fold.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-09-01 19:56:15 +0200
committerBram Moolenaar <Bram@vim.org>2020-09-01 19:56:15 +0200
commit9c2b06637b32742cac11bfd66b1a4e84583c6c2e (patch)
tree6f193fe923afd59dd8ac369bd58e9ae32fc06ae2 /src/fold.c
parentca563b9b948aec18463c26e9f87ae7933571b40e (diff)
patch 8.2.1560: using NULL pointers in some codev8.2.1560
Problem: Using NULL pointers in some code. (James McCoy) Solution: Avoid adding to a NULL pointer. Use byte as unsigned.
Diffstat (limited to 'src/fold.c')
-rw-r--r--src/fold.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/fold.c b/src/fold.c
index 3c106d25cf..d95b46b5b4 100644
--- a/src/fold.c
+++ b/src/fold.c
@@ -1314,7 +1314,7 @@ setManualFoldWin(
if (!foldFind(gap, lnum, &fp))
{
// If there is a following fold, continue there next time.
- if (fp < (fold_T *)gap->ga_data + gap->ga_len)
+ if (fp != NULL && fp < (fold_T *)gap->ga_data + gap->ga_len)
next = fp->fd_top + off;
break;
}
@@ -2905,18 +2905,20 @@ foldSplit(
// any between top and bot, they have been removed by the caller.
gap1 = &fp->fd_nested;
gap2 = &fp[1].fd_nested;
- (void)(foldFind(gap1, bot + 1 - fp->fd_top, &fp2));
- len = (int)((fold_T *)gap1->ga_data + gap1->ga_len - fp2);
- if (len > 0 && ga_grow(gap2, len) == OK)
+ if (foldFind(gap1, bot + 1 - fp->fd_top, &fp2))
{
- for (idx = 0; idx < len; ++idx)
+ len = (int)((fold_T *)gap1->ga_data + gap1->ga_len - fp2);
+ if (len > 0 && ga_grow(gap2, len) == OK)
{
- ((fold_T *)gap2->ga_data)[idx] = fp2[idx];
- ((fold_T *)gap2->ga_data)[idx].fd_top
- -= fp[1].fd_top - fp->fd_top;
+ for (idx = 0; idx < len; ++idx)
+ {
+ ((fold_T *)gap2->ga_data)[idx] = fp2[idx];
+ ((fold_T *)gap2->ga_data)[idx].fd_top
+ -= fp[1].fd_top - fp->fd_top;
+ }
+ gap2->ga_len = len;
+ gap1->ga_len -= len;
}
- gap2->ga_len = len;
- gap1->ga_len -= len;
}
fp->fd_len = top - fp->fd_top;
fold_changed = TRUE;