comparison src/fold.c @ 22008:3ea6b4a5369a

patch 8.2.1553: crash in edit test Commit: https://github.com/vim/vim/commit/2c93c685e3334c50d9a748ad699df727a4501b08 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Aug 31 21:15:02 2020 +0200 patch 8.2.1553: crash in edit test Problem: Crash in edit test. Solution: Avoid using invalid pointer.
author Bram Moolenaar <Bram@vim.org>
date Mon, 31 Aug 2020 21:15:17 +0200
parents 468569085ab2
children 24cef4317d92
comparison
equal deleted inserted replaced
22007:4c7310b17a0e 22008:3ea6b4a5369a
606 606
607 checkupdate(curwin); 607 checkupdate(curwin);
608 608
609 // Find the place to insert the new fold. 609 // Find the place to insert the new fold.
610 gap = &curwin->w_folds; 610 gap = &curwin->w_folds;
611 for (;;) 611 if (gap->ga_len == 0)
612 { 612 i = 0;
613 if (!foldFind(gap, start_rel, &fp)) 613 else
614 break; 614 {
615 if (fp->fd_top + fp->fd_len > end_rel) 615 for (;;)
616 { 616 {
617 // New fold is completely inside this fold: Go one level deeper. 617 if (!foldFind(gap, start_rel, &fp))
618 gap = &fp->fd_nested; 618 break;
619 start_rel -= fp->fd_top; 619 if (fp->fd_top + fp->fd_len > end_rel)
620 end_rel -= fp->fd_top; 620 {
621 if (use_level || fp->fd_flags == FD_LEVEL) 621 // New fold is completely inside this fold: Go one level
622 { 622 // deeper.
623 use_level = TRUE; 623 gap = &fp->fd_nested;
624 if (level >= curwin->w_p_fdl) 624 start_rel -= fp->fd_top;
625 end_rel -= fp->fd_top;
626 if (use_level || fp->fd_flags == FD_LEVEL)
627 {
628 use_level = TRUE;
629 if (level >= curwin->w_p_fdl)
630 closed = TRUE;
631 }
632 else if (fp->fd_flags == FD_CLOSED)
625 closed = TRUE; 633 closed = TRUE;
626 } 634 ++level;
627 else if (fp->fd_flags == FD_CLOSED) 635 }
628 closed = TRUE; 636 else
629 ++level; 637 {
630 } 638 // This fold and new fold overlap: Insert here and move some
631 else 639 // folds inside the new fold.
632 { 640 break;
633 // This fold and new fold overlap: Insert here and move some folds 641 }
634 // inside the new fold. 642 }
635 break; 643 i = (int)(fp - (fold_T *)gap->ga_data);
636 } 644 }
637 } 645
638
639 i = (int)(fp - (fold_T *)gap->ga_data);
640 if (ga_grow(gap, 1) == OK) 646 if (ga_grow(gap, 1) == OK)
641 { 647 {
642 fp = (fold_T *)gap->ga_data + i; 648 fp = (fold_T *)gap->ga_data + i;
643 ga_init2(&fold_ga, (int)sizeof(fold_T), 10); 649 ga_init2(&fold_ga, (int)sizeof(fold_T), 10);
644 650