Skip to content

Commit bba7980

Browse files
committed
patch 9.1.0309: crash when 'textwidth' > MAX_INT
Problem: crash when 'textwidth' > MAX_INT (after vv9.1.0055) (Zoltan Balogh) Solution: limit textwidth to MAX_INT fixes: #14482 closes: #14489 Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 7b0c4b6 commit bba7980

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/testdir/test_textformat.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,4 +1303,13 @@ func Test_correct_cursor_position()
13031303
set encoding=utf8
13041304
endfunc
13051305

1306+
" This was crashing Vim
1307+
func Test_textwdith_overflow()
1308+
new
1309+
setl tw=999999999
1310+
normal 10ig
1311+
call feedkeys('a ab cd ef', 'xt')
1312+
bw!
1313+
endfunc
1314+
13061315
" vim: shiftwidth=2 sts=2 expandtab

src/textformat.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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;

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
309,
707709
/**/
708710
308,
709711
/**/

0 commit comments

Comments
 (0)