Mercurial > vim
comparison src/indent.c @ 27000:8c0730eca2ce v8.2.4029
patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Commit: https://github.com/vim/vim/commit/b2d85e3784ac89f5209489844c1ee0f54d117abb
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Jan 7 16:55:32 2022 +0000
patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Problem: Debugging NFA regexp my crash, cached indent may be wrong.
Solution: Fix some debug warnings in the NFA regexp code. Make sure log_fd
is set when used. Fix breakindent and indent caching. (Christian
Brabandt, closes #9482)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 07 Jan 2022 18:00:04 +0100 |
parents | 06a137af96f8 |
children | 164d59ddd48a |
comparison
equal
deleted
inserted
replaced
26999:aba0728a28d9 | 27000:8c0730eca2ce |
---|---|
913 int | 913 int |
914 get_breakindent_win( | 914 get_breakindent_win( |
915 win_T *wp, | 915 win_T *wp, |
916 char_u *line) // start of the line | 916 char_u *line) // start of the line |
917 { | 917 { |
918 static int prev_indent = 0; // cached indent value | 918 static int prev_indent = 0; // cached indent value |
919 static long prev_ts = 0L; // cached tabstop value | 919 static long prev_ts = 0L; // cached tabstop value |
920 static char_u *prev_line = NULL; // cached pointer to line | 920 static char_u *prev_line = NULL; // cached pointer to line |
921 static varnumber_T prev_tick = 0; // changedtick of cached value | 921 static varnumber_T prev_tick = 0; // changedtick of cached value |
922 # ifdef FEAT_VARTABS | 922 # ifdef FEAT_VARTABS |
923 static int *prev_vts = NULL; // cached vartabs values | 923 static int *prev_vts = NULL; // cached vartabs values |
924 # endif | 924 # endif |
925 static int prev_list = 0; // cached list value | |
926 static int prev_listopt = 0; // cached w_p_briopt_list value | |
925 int bri = 0; | 927 int bri = 0; |
926 // window width minus window margin space, i.e. what rests for text | 928 // window width minus window margin space, i.e. what rests for text |
927 const int eff_wwidth = wp->w_width | 929 const int eff_wwidth = wp->w_width |
928 - ((wp->w_p_nu || wp->w_p_rnu) | 930 - ((wp->w_p_nu || wp->w_p_rnu) |
929 && (vim_strchr(p_cpo, CPO_NUMCOL) == NULL) | 931 && (vim_strchr(p_cpo, CPO_NUMCOL) == NULL) |
930 ? number_width(wp) + 1 : 0); | 932 ? number_width(wp) + 1 : 0); |
931 | 933 |
932 // used cached indent, unless pointer or 'tabstop' changed | 934 // used cached indent, unless line, 'tabstop' or briopt_list changed |
933 if (prev_line != line || prev_ts != wp->w_buffer->b_p_ts | 935 if (prev_line != line || prev_ts != wp->w_buffer->b_p_ts |
934 || prev_tick != CHANGEDTICK(wp->w_buffer) | 936 || prev_tick != CHANGEDTICK(wp->w_buffer) |
937 || prev_listopt != wp->w_briopt_list | |
935 # ifdef FEAT_VARTABS | 938 # ifdef FEAT_VARTABS |
936 || prev_vts != wp->w_buffer->b_p_vts_array | 939 || prev_vts != wp->w_buffer->b_p_vts_array |
937 # endif | 940 # endif |
938 ) | 941 ) |
939 { | 942 { |
947 wp->w_buffer->b_p_vts_array, wp->w_p_list); | 950 wp->w_buffer->b_p_vts_array, wp->w_p_list); |
948 # else | 951 # else |
949 prev_indent = get_indent_str(line, | 952 prev_indent = get_indent_str(line, |
950 (int)wp->w_buffer->b_p_ts, wp->w_p_list); | 953 (int)wp->w_buffer->b_p_ts, wp->w_p_list); |
951 # endif | 954 # endif |
955 prev_listopt = wp->w_briopt_list; | |
956 // add additional indent for numbered lists | |
957 if (wp->w_briopt_list != 0) | |
958 { | |
959 regmatch_T regmatch; | |
960 | |
961 regmatch.regprog = vim_regcomp(curbuf->b_p_flp, | |
962 RE_MAGIC + RE_STRING + RE_AUTO + RE_STRICT); | |
963 | |
964 if (regmatch.regprog != NULL) | |
965 { | |
966 regmatch.rm_ic = FALSE; | |
967 if (vim_regexec(®match, line, 0)) | |
968 { | |
969 if (wp->w_briopt_list > 0) | |
970 prev_list = wp->w_briopt_list; | |
971 else | |
972 prev_list = (*regmatch.endp - *regmatch.startp); | |
973 } | |
974 vim_regfree(regmatch.regprog); | |
975 } | |
976 } | |
952 } | 977 } |
953 bri = prev_indent + wp->w_briopt_shift; | 978 bri = prev_indent + wp->w_briopt_shift; |
954 | 979 |
955 // Add offset for number column, if 'n' is in 'cpoptions' | 980 // Add offset for number column, if 'n' is in 'cpoptions' |
956 bri += win_col_off2(wp); | 981 bri += win_col_off2(wp); |
957 | 982 |
958 // add additional indent for numbered lists | 983 // add additional indent for numbered lists |
959 if (wp->w_briopt_list != 0) | 984 if (wp->w_briopt_list != 0) |
960 { | 985 { |
961 regmatch_T regmatch; | 986 if (wp->w_briopt_list > 0) |
962 | 987 bri += prev_list; |
963 regmatch.regprog = vim_regcomp(curbuf->b_p_flp, | 988 else |
964 RE_MAGIC + RE_STRING + RE_AUTO + RE_STRICT); | 989 bri = prev_list; |
965 if (regmatch.regprog != NULL) | |
966 { | |
967 regmatch.rm_ic = FALSE; | |
968 if (vim_regexec(®match, line, 0)) | |
969 { | |
970 if (wp->w_briopt_list > 0) | |
971 bri += wp->w_briopt_list; | |
972 else | |
973 bri = (*regmatch.endp - *regmatch.startp); | |
974 } | |
975 vim_regfree(regmatch.regprog); | |
976 } | |
977 } | 990 } |
978 | 991 |
979 // indent minus the length of the showbreak string | 992 // indent minus the length of the showbreak string |
980 if (wp->w_briopt_sbr) | 993 if (wp->w_briopt_sbr) |
981 bri -= vim_strsize(get_showbreak_value(wp)); | 994 bri -= vim_strsize(get_showbreak_value(wp)); |