mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 14:08:32 +00:00
fold: declare and init vars in deleteFoldEntry()
Use sizeof() on pointer value, not explicit type, for memmove.
This commit is contained in:
@@ -1295,17 +1295,14 @@ static void foldOpenNested(fold_T *fpr)
|
|||||||
static void deleteFoldEntry(garray_T *const gap, const int idx,
|
static void deleteFoldEntry(garray_T *const gap, const int idx,
|
||||||
const bool recursive)
|
const bool recursive)
|
||||||
{
|
{
|
||||||
fold_T *fp;
|
fold_T *fp = (fold_T *)gap->ga_data + idx;
|
||||||
int i;
|
|
||||||
fold_T *nfp;
|
|
||||||
|
|
||||||
fp = (fold_T *)gap->ga_data + idx;
|
|
||||||
if (recursive || GA_EMPTY(&fp->fd_nested)) {
|
if (recursive || GA_EMPTY(&fp->fd_nested)) {
|
||||||
/* recursively delete the contained folds */
|
// recursively delete the contained folds
|
||||||
deleteFoldRecurse(&fp->fd_nested);
|
deleteFoldRecurse(&fp->fd_nested);
|
||||||
--gap->ga_len;
|
gap->ga_len--;
|
||||||
if (idx < gap->ga_len)
|
if (idx < gap->ga_len) {
|
||||||
memmove(fp, fp + 1, sizeof(fold_T) * (size_t)(gap->ga_len - idx));
|
memmove(fp, fp + 1, sizeof(*fp) * (size_t)(gap->ga_len - idx));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Move nested folds one level up, to overwrite the fold that is
|
/* Move nested folds one level up, to overwrite the fold that is
|
||||||
* deleted. */
|
* deleted. */
|
||||||
@@ -1315,9 +1312,9 @@ static void deleteFoldEntry(garray_T *const gap, const int idx,
|
|||||||
/* Get "fp" again, the array may have been reallocated. */
|
/* Get "fp" again, the array may have been reallocated. */
|
||||||
fp = (fold_T *)gap->ga_data + idx;
|
fp = (fold_T *)gap->ga_data + idx;
|
||||||
|
|
||||||
/* adjust fd_top and fd_flags for the moved folds */
|
// adjust fd_top and fd_flags for the moved folds
|
||||||
nfp = (fold_T *)fp->fd_nested.ga_data;
|
fold_T *nfp = (fold_T *)fp->fd_nested.ga_data;
|
||||||
for (i = 0; i < moved; ++i) {
|
for (int i = 0; i < moved; i++) {
|
||||||
nfp[i].fd_top += fp->fd_top;
|
nfp[i].fd_top += fp->fd_top;
|
||||||
if (fp->fd_flags == FD_LEVEL)
|
if (fp->fd_flags == FD_LEVEL)
|
||||||
nfp[i].fd_flags = FD_LEVEL;
|
nfp[i].fd_flags = FD_LEVEL;
|
||||||
@@ -1326,12 +1323,13 @@ static void deleteFoldEntry(garray_T *const gap, const int idx,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* move the existing folds down to make room */
|
// move the existing folds down to make room
|
||||||
if (idx + 1 < gap->ga_len)
|
if (idx + 1 < gap->ga_len) {
|
||||||
memmove(fp + moved, fp + 1,
|
memmove(fp + moved, fp + 1,
|
||||||
sizeof(fold_T) * (size_t)(gap->ga_len - (idx + 1)));
|
sizeof(*fp) * (size_t)(gap->ga_len - (idx + 1)));
|
||||||
/* move the contained folds one level up */
|
}
|
||||||
memmove(fp, nfp, sizeof(fold_T) * (size_t)moved);
|
// move the contained folds one level up
|
||||||
|
memmove(fp, nfp, sizeof(*fp) * (size_t)moved);
|
||||||
xfree(nfp);
|
xfree(nfp);
|
||||||
gap->ga_len += moved - 1;
|
gap->ga_len += moved - 1;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user