0
0
mirror of https://github.com/vim/vim.git synced 2025-09-29 04:34:16 -04:00

patch 8.1.0479: failure when setting 'varsofttabstop' to end in a comma

Problem:    Failure when setting 'varsofttabstop' to end in a comma. (Ralf
            Schandl)
Solution:   Reject value with trailing command.  Add test for invalid values
            (closes #3544)
This commit is contained in:
Bram Moolenaar
2018-10-15 22:51:50 +02:00
parent 65dc12143a
commit 64f410742f
3 changed files with 26 additions and 12 deletions

View File

@@ -12786,17 +12786,18 @@ tabstop_set(char_u *var, int **array)
int t; int t;
char_u *cp; char_u *cp;
if ((!var[0] || (var[0] == '0' && !var[1]))) if (var[0] == NUL || (var[0] == '0' && var[1] == NUL))
{ {
*array = NULL; *array = NULL;
return TRUE; return TRUE;
} }
for (cp = var; *cp; ++cp) for (cp = var; *cp != NUL; ++cp)
{ {
if (cp == var || *(cp - 1) == ',') if (cp == var || cp[-1] == ',')
{ {
char_u *end; char_u *end;
if (strtol((char *)cp, (char **)&end, 10) <= 0) if (strtol((char *)cp, (char **)&end, 10) <= 0)
{ {
if (cp != end) if (cp != end)
@@ -12809,7 +12810,7 @@ tabstop_set(char_u *var, int **array)
if (VIM_ISDIGIT(*cp)) if (VIM_ISDIGIT(*cp))
continue; continue;
if (*cp == ',' && cp > var && *(cp - 1) != ',') if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL)
{ {
++valcount; ++valcount;
continue; continue;
@@ -12818,16 +12819,16 @@ tabstop_set(char_u *var, int **array)
return FALSE; return FALSE;
} }
*array = (int *) alloc((unsigned) ((valcount + 1) * sizeof(int))); *array = (int *)alloc((unsigned) ((valcount + 1) * sizeof(int)));
(*array)[0] = valcount; (*array)[0] = valcount;
t = 1; t = 1;
for (cp = var; *cp;) for (cp = var; *cp != NUL;)
{ {
(*array)[t++] = atoi((char *)cp); (*array)[t++] = atoi((char *)cp);
while (*cp && *cp != ',') while (*cp != NUL && *cp != ',')
++cp; ++cp;
if (*cp) if (*cp != NUL)
++cp; ++cp;
} }

View File

@@ -5,11 +5,11 @@ if !has("vartabs")
endif endif
source view_util.vim source view_util.vim
function! s:compare_lines(expect, actual) func s:compare_lines(expect, actual)
call assert_equal(join(a:expect, "\n"), join(a:actual, "\n")) call assert_equal(join(a:expect, "\n"), join(a:actual, "\n"))
endfunction endfunc
func! Test_vartabs() func Test_vartabs()
new new
%d %d
@@ -261,7 +261,7 @@ func! Test_vartabs_breakindent()
bwipeout! bwipeout!
endfunc endfunc
func! Test_vartabs_linebreak() func Test_vartabs_linebreak()
if winwidth(0) < 40 if winwidth(0) < 40
return return
endif endif
@@ -296,3 +296,14 @@ func! Test_vartabs_linebreak()
bw! bw!
set nolist listchars&vim set nolist listchars&vim
endfunc endfunc
func Test_vartabs_failures()
call assert_fails('set vts=8,')
call assert_fails('set vsts=8,')
call assert_fails('set vts=8,,8')
call assert_fails('set vsts=8,,8')
call assert_fails('set vts=8,,8,')
call assert_fails('set vsts=8,,8,')
call assert_fails('set vts=,8')
call assert_fails('set vsts=,8')
endfunc

View File

@@ -792,6 +792,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
479,
/**/ /**/
478, 478,
/**/ /**/