On So, 24 Jun 2018, Bram Moolenaar wrote:
> Thanks.  Can we make the test work with a narrower window?  Mostly 80
> chars is used, I don't think the CI runs with a larger terminal,
> resulting in the test being skipped.

Here is a new patch, which fixes a couple of remaining vartabs issues 
and adds some more tests.

Best,
Christian
-- 
Die Personen können sich am leichtesten verstellen, die vorher gut
waren; wie Schauspieler die Rollen, die ihrer natürlichen am nächsten
kommen, gut spielen.
                -- Jean Paul

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
From 4da3fd872c41b9057585266e0993643bfdaf3594 Mon Sep 17 00:00:00 2001
From: Christian Brabandt <[email protected]>
Date: Sun, 24 Jun 2018 21:09:28 +0200
Subject: [PATCH] Fix remaining issues for vartab feature

This patch does the following:

- fix a memory leak in ex_retab
- prevent a division by zero in tabstop_fromto (coverity CID 1437494)
- Make sure, that the screen drawing code does take the variable tabstop
  into account
- Fix a segfault in screen.c when n_extra < tab_len (which would result
  in a smaller len value which could cause a segfault in the following
  `for (i=0; i<tab_len; i++)` loop (the loop is supposed to be run per
  characters and not per bytes).
- Add a test for 3 (github issue #3076)
---
 src/ex_cmds.c                |  2 +-
 src/option.c                 |  8 ++++++-
 src/screen.c                 |  8 +++++++
 src/testdir/test_vartabs.vim | 41 ++++++++++++++++++++++++++++++++++++
 4 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index 53334342c..ffde0ee7b 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -857,7 +857,6 @@ ex_retab(exarg_T *eap)
 	{
 	    set_string_option_direct((char_u *)"vts", -1, new_ts_str,
 							OPT_FREE|OPT_LOCAL, 0);
-	    vim_free(new_ts_str);
 	    curbuf->b_p_vts_array = new_ts;
 	    vim_free(old_vts_ary);
 	}
@@ -868,6 +867,7 @@ ex_retab(exarg_T *eap)
 	    curbuf->b_p_ts = tabstop_first(new_ts);
 	    vim_free(new_ts);
 	}
+	vim_free(new_ts_str);
     }
 #else
     curbuf->b_p_ts = new_ts;
diff --git a/src/option.c b/src/option.c
index 94cd7aa52..897f4c35f 100644
--- a/src/option.c
+++ b/src/option.c
@@ -12877,7 +12877,13 @@ tabstop_fromto(
     if (vts == 0 || vts[0] == 0)
     {
 	int tabs = 0;
-	int initspc = ts - (start_col % ts);
+	int initspc = 0;
+
+	if (ts == 0)
+	    /* no division by zero */
+	    ts = curbuf->b_p_ts;
+
+	initspc = ts - (start_col % ts);
 	if (spaces >= initspc)
 	{
 	    spaces -= initspc;
diff --git a/src/screen.c b/src/screen.c
index b5b68e4df..b20de1067 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -4753,8 +4753,13 @@ win_line(
 		    n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol,
 								    NULL) - 1;
 		    if (c == TAB && n_extra + col > wp->w_width)
+ #ifdef FEAT_VARTABS
+			n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts,
+					wp->w_buffer->b_p_vts_array) - 1;
+#else
 			n_extra = (int)wp->w_buffer->b_p_ts
 				       - vcol % (int)wp->w_buffer->b_p_ts - 1;
+ #endif
 
 # ifdef FEAT_MBYTE
 		    c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
@@ -4889,6 +4894,9 @@ win_line(
 			if (n_extra > 0)
 			    len += n_extra - tab_len;
 #endif
+			/* adjust tab_len to the actual used len */
+			if (n_extra < tab_len)
+			    tab_len += n_extra - tab_len;
 			c = lcs_tab1;
 			p = alloc((unsigned)(len + 1));
 			vim_memset(p, ' ', len);
diff --git a/src/testdir/test_vartabs.vim b/src/testdir/test_vartabs.vim
index 85914f6bc..b69b1d9a9 100644
--- a/src/testdir/test_vartabs.vim
+++ b/src/testdir/test_vartabs.vim
@@ -4,6 +4,11 @@ if !has("vartabs")
   finish
 endif
 
+source view_util.vim
+function! s:compare_lines(expect, actual)
+  call assert_equal(join(a:expect, "\n"), join(a:actual, "\n"))
+endfunction
+
 func! Test_vartabs()
   new
   %d
@@ -255,3 +260,39 @@ func! Test_vartabs_breakindent()
 
   bwipeout!
 endfunc
+
+func! Test_vartabs_linebreak()
+  return
+  if winwidth(0) < 40
+    return
+  endif
+  new
+  40vnew
+  %d
+  setl linebreak vartabstop=10,20,30,40
+  call setline(1, "\tx\tx\tx\tx")
+
+  let expect = ['          x                             ',
+        \       'x                   x                   ',
+        \       'x                                       ']
+  let lines = ScreenLines([1, 3], winwidth(0))
+  call s:compare_lines(expect, lines)
+  setl list listchars=tab:>-
+  let expect = ['>---------x>------------------          ',
+        \       'x>------------------x>------------------',
+        \       'x                                       ']
+  let lines = ScreenLines([1, 3], winwidth(0))
+  call s:compare_lines(expect, lines)
+  setl linebreak vartabstop=40
+  let expect = ['>---------------------------------------',
+        \       'x>--------------------------------------',
+        \       'x>--------------------------------------',
+        \       'x>--------------------------------------',
+        \       'x                                       ']
+  let lines = ScreenLines([1, 5], winwidth(0))
+  call s:compare_lines(expect, lines)
+
+  " cleanup
+  bw!
+  bw!
+endfunc
-- 
2.17.0

Raspunde prin e-mail lui