comparison src/drawline.c @ 25711:d1457c3f156c v8.2.3391

patch 8.2.3391: crash with combination of 'linebreak' and other options Commit: https://github.com/vim/vim/commit/20e0c3d27bda770542c1c0e4c81fd6443c12f3a6 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Aug 31 20:57:55 2021 +0200 patch 8.2.3391: crash with combination of 'linebreak' and other options Problem: Crash with combination of 'linebreak' and other options. Solution: Avoid n_extra to become negative. (Christian Brabandt, closes #8817)
author Bram Moolenaar <Bram@vim.org>
date Tue, 31 Aug 2021 21:00:06 +0200
parents b04e76e66128
children 24b80aa4dd2e
comparison
equal deleted inserted replaced
25710:3d6603826015 25711:d1457c3f156c
1968 #ifdef FEAT_LINEBREAK 1968 #ifdef FEAT_LINEBREAK
1969 // Found last space before word: check for line break. 1969 // Found last space before word: check for line break.
1970 if (wp->w_p_lbr && c0 == c 1970 if (wp->w_p_lbr && c0 == c
1971 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr)) 1971 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
1972 { 1972 {
1973 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1) : 0; 1973 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
1974 char_u *p = ptr - (mb_off + 1); 1974 : 0;
1975 char_u *p = ptr - (mb_off + 1);
1975 1976
1976 // TODO: is passing p for start of the line OK? 1977 // TODO: is passing p for start of the line OK?
1977 n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol, 1978 n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol,
1978 NULL) - 1; 1979 NULL) - 1;
1979 1980
1980 // We have just drawn the showbreak value, no need to add 1981 // We have just drawn the showbreak value, no need to add
1981 // space for it again 1982 // space for it again.
1982 if (vcol == vcol_sbr) 1983 if (vcol == vcol_sbr)
1984 {
1983 n_extra -= MB_CHARLEN(get_showbreak_value(wp)); 1985 n_extra -= MB_CHARLEN(get_showbreak_value(wp));
1986 if (n_extra < 0)
1987 n_extra = 0;
1988 }
1984 1989
1985 if (c == TAB && n_extra + col > wp->w_width) 1990 if (c == TAB && n_extra + col > wp->w_width)
1986 # ifdef FEAT_VARTABS 1991 # ifdef FEAT_VARTABS
1987 n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts, 1992 n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts,
1988 wp->w_buffer->b_p_vts_array) - 1; 1993 wp->w_buffer->b_p_vts_array) - 1;