Mercurial > vim
comparison src/fold.c @ 22006:468569085ab2 v8.2.1552
patch 8.2.1552: warnings from asan with clang-11
Commit: https://github.com/vim/vim/commit/64f37d309025a65210dbc33823ec9ec5d547775f
Author: Bram Moolenaar <Bram@vim.org>
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)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 31 Aug 2020 20:00:05 +0200 |
parents | 3af71cbcfdbe |
children | 3ea6b4a5369a |
comparison
equal
deleted
inserted
replaced
22005:ea3ef673c28f | 22006:468569085ab2 |
---|---|
818 if (need_diff_redraw) | 818 if (need_diff_redraw) |
819 // will update later | 819 // will update later |
820 return; | 820 return; |
821 #endif | 821 #endif |
822 | 822 |
823 // Mark all folds from top to bot as maybe-small. | 823 if (wp->w_folds.ga_len > 0) |
824 (void)foldFind(&wp->w_folds, top, &fp); | 824 { |
825 while (fp < (fold_T *)wp->w_folds.ga_data + wp->w_folds.ga_len | 825 // Mark all folds from top to bot as maybe-small. |
826 && fp->fd_top < bot) | 826 (void)foldFind(&wp->w_folds, top, &fp); |
827 { | 827 while (fp < (fold_T *)wp->w_folds.ga_data + wp->w_folds.ga_len |
828 fp->fd_small = MAYBE; | 828 && fp->fd_top < bot) |
829 ++fp; | 829 { |
830 fp->fd_small = MAYBE; | |
831 ++fp; | |
832 } | |
830 } | 833 } |
831 | 834 |
832 if (foldmethodIsIndent(wp) | 835 if (foldmethodIsIndent(wp) |
833 || foldmethodIsExpr(wp) | 836 || foldmethodIsExpr(wp) |
834 || foldmethodIsMarker(wp) | 837 || foldmethodIsMarker(wp) |
1124 foldFind(garray_T *gap, linenr_T lnum, fold_T **fpp) | 1127 foldFind(garray_T *gap, linenr_T lnum, fold_T **fpp) |
1125 { | 1128 { |
1126 linenr_T low, high; | 1129 linenr_T low, high; |
1127 fold_T *fp; | 1130 fold_T *fp; |
1128 int i; | 1131 int i; |
1132 | |
1133 if (gap->ga_len == 0) | |
1134 { | |
1135 *fpp = NULL; | |
1136 return FALSE; | |
1137 } | |
1129 | 1138 |
1130 /* | 1139 /* |
1131 * Perform a binary search. | 1140 * Perform a binary search. |
1132 * "low" is lowest index of possible match. | 1141 * "low" is lowest index of possible match. |
1133 * "high" is highest index of possible match. | 1142 * "high" is highest index of possible match. |
2498 concat = 1; | 2507 concat = 1; |
2499 | 2508 |
2500 // Find an existing fold to re-use. Preferably one that | 2509 // Find an existing fold to re-use. Preferably one that |
2501 // includes startlnum, otherwise one that ends just before | 2510 // includes startlnum, otherwise one that ends just before |
2502 // startlnum or starts after it. | 2511 // startlnum or starts after it. |
2503 if (foldFind(gap, startlnum, &fp) | 2512 if (gap->ga_len > 0 && (foldFind(gap, startlnum, &fp) |
2504 || (fp < ((fold_T *)gap->ga_data) + gap->ga_len | 2513 || (fp < ((fold_T *)gap->ga_data) + gap->ga_len |
2505 && fp->fd_top <= firstlnum) | 2514 && fp->fd_top <= firstlnum) |
2506 || foldFind(gap, firstlnum - concat, &fp) | 2515 || foldFind(gap, firstlnum - concat, &fp) |
2507 || (fp < ((fold_T *)gap->ga_data) + gap->ga_len | 2516 || (fp < ((fold_T *)gap->ga_data) + gap->ga_len |
2508 && ((lvl < level && fp->fd_top < flp->lnum) | 2517 && ((lvl < level && fp->fd_top < flp->lnum) |
2509 || (lvl >= level | 2518 || (lvl >= level |
2510 && fp->fd_top <= flp->lnum_save)))) | 2519 && fp->fd_top <= flp->lnum_save))))) |
2511 { | 2520 { |
2512 if (fp->fd_top + fp->fd_len + concat > firstlnum) | 2521 if (fp->fd_top + fp->fd_len + concat > firstlnum) |
2513 { | 2522 { |
2514 // Use existing fold for the new fold. If it starts | 2523 // Use existing fold for the new fold. If it starts |
2515 // before where we started looking, extend it. If it | 2524 // before where we started looking, extend it. If it |
2620 } | 2629 } |
2621 else | 2630 else |
2622 { | 2631 { |
2623 // Insert new fold. Careful: ga_data may be NULL and it | 2632 // Insert new fold. Careful: ga_data may be NULL and it |
2624 // may change! | 2633 // may change! |
2625 i = (int)(fp - (fold_T *)gap->ga_data); | 2634 if (gap->ga_len == 0) |
2635 i = 0; | |
2636 else | |
2637 i = (int)(fp - (fold_T *)gap->ga_data); | |
2626 if (foldInsert(gap, i) != OK) | 2638 if (foldInsert(gap, i) != OK) |
2627 return bot; | 2639 return bot; |
2628 fp = (fold_T *)gap->ga_data + i; | 2640 fp = (fold_T *)gap->ga_data + i; |
2629 // The new fold continues until bot, unless we find the | 2641 // The new fold continues until bot, unless we find the |
2630 // end earlier. | 2642 // end earlier. |
2839 fold_T *fp; | 2851 fold_T *fp; |
2840 | 2852 |
2841 if (ga_grow(gap, 1) != OK) | 2853 if (ga_grow(gap, 1) != OK) |
2842 return FAIL; | 2854 return FAIL; |
2843 fp = (fold_T *)gap->ga_data + i; | 2855 fp = (fold_T *)gap->ga_data + i; |
2844 if (i < gap->ga_len) | 2856 if (gap->ga_len > 0 && i < gap->ga_len) |
2845 mch_memmove(fp + 1, fp, sizeof(fold_T) * (gap->ga_len - i)); | 2857 mch_memmove(fp + 1, fp, sizeof(fold_T) * (gap->ga_len - i)); |
2846 ++gap->ga_len; | 2858 ++gap->ga_len; |
2847 ga_init2(&fp->fd_nested, (int)sizeof(fold_T), 10); | 2859 ga_init2(&fp->fd_nested, (int)sizeof(fold_T), 10); |
2848 return OK; | 2860 return OK; |
2849 } | 2861 } |
2926 fold_T *fp = NULL; | 2938 fold_T *fp = NULL; |
2927 | 2939 |
2928 if (bot < top) | 2940 if (bot < top) |
2929 return; // nothing to do | 2941 return; // nothing to do |
2930 | 2942 |
2931 for (;;) | 2943 while (gap->ga_len > 0) |
2932 { | 2944 { |
2933 // Find fold that includes top or a following one. | 2945 // Find fold that includes top or a following one. |
2934 if (foldFind(gap, top, &fp) && fp->fd_top < top) | 2946 if (foldFind(gap, top, &fp) && fp->fd_top < top) |
2935 { | 2947 { |
2936 // 2: or 3: need to delete nested folds | 2948 // 2: or 3: need to delete nested folds |