File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1303,4 +1303,13 @@ func Test_correct_cursor_position()
13031303 set encoding = utf8
13041304endfunc
13051305
1306+ " This was crashing Vim
1307+ func Test_textwdith_overflow ()
1308+ new
1309+ setl tw = 999999999
1310+ normal 10 ig
1311+ call feedkeys (' a ab cd ef' , ' xt' )
1312+ bw !
1313+ endfunc
1314+
13061315" vim: shiftwidth = 2 sts = 2 expandtab
Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ internal_format(
5656 colnr_T leader_len ;
5757 int no_leader = FALSE;
5858 int do_comments = (flags & INSCHAR_DO_COM );
59+ int safe_tw = trim_to_int (8 * (vimlong_T )textwidth );
5960#ifdef FEAT_LINEBREAK
6061 int has_lbr = curwin -> w_p_lbr ;
6162
@@ -95,7 +96,7 @@ internal_format(
9596 // Cursor is currently at the end of line. No need to format
9697 // if line length is less than textwidth (8 * textwidth for
9798 // utf safety)
98- if (curwin -> w_cursor .col < 8 * textwidth )
99+ if (curwin -> w_cursor .col < safe_tw )
99100 {
100101 virtcol = get_nolist_virtcol ()
101102 + char2cells (c != NUL ? c : gchar_cursor ());
@@ -156,8 +157,7 @@ internal_format(
156157 // line to textwidth border every time for each line break.
157158 //
158159 // Ceil to 8 * textwidth to optimize.
159- curwin -> w_cursor .col = startcol < 8 * textwidth ? startcol :
160- 8 * textwidth ;
160+ curwin -> w_cursor .col = startcol < safe_tw ? startcol : safe_tw ;
161161
162162 foundcol = 0 ;
163163 skip_pos = 0 ;
Original file line number Diff line number Diff line change @@ -704,6 +704,8 @@ static char *(features[]) =
704704
705705static int included_patches [] =
706706{ /* Add new patch number below this line */
707+ /**/
708+ 309 ,
707709/**/
708710 308 ,
709711/**/
You can’t perform that action at this time.
0 commit comments