vim-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 vim/vim#3544)
64f410742f
This commit is contained in:
VVKot
2021-01-31 18:01:37 +00:00
parent 6f23291b8d
commit facb1d897e
2 changed files with 23 additions and 11 deletions

View File

@@ -7083,14 +7083,15 @@ bool tabstop_set(char_u *var, long **array)
int t;
char_u *cp;
if ((!var[0] || (var[0] == '0' && !var[1]))) {
if (var[0] == NUL || (var[0] == '0' && var[1] == NUL)) {
*array = NULL;
return true;
}
for (cp = var; *cp; cp++) {
if (cp == var || *(cp - 1) == ',') {
for (cp = var; *cp != NUL; cp++) {
if (cp == var || cp[-1] == ',') {
char_u *end;
if (strtol((char *)cp, (char **)&end, 10) <= 0) {
if (cp != end) {
EMSG(_(e_positive));
@@ -7104,7 +7105,7 @@ bool tabstop_set(char_u *var, long **array)
if (ascii_isdigit(*cp)) {
continue;
}
if (*cp == ',' && cp > var && *(cp - 1) != ',') {
if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL) {
valcount++;
continue;
}
@@ -7116,12 +7117,12 @@ bool tabstop_set(char_u *var, long **array)
(*array)[0] = valcount;
t = 1;
for (cp = var; *cp;) {
for (cp = var; *cp != NUL;) {
(*array)[t++] = atoi((char *)cp);
while (*cp && *cp != ',') {
while (*cp != NUL && *cp != ',') {
cp++;
}
if (*cp) {
if (*cp != NUL) {
cp++;
}
}

View File

@@ -5,11 +5,11 @@ if !has("vartabs")
endif
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"))
endfunction
endfunc
func! Test_vartabs()
func Test_vartabs()
new
%d
@@ -261,7 +261,7 @@ func! Test_vartabs_breakindent()
bwipeout!
endfunc
func! Test_vartabs_linebreak()
func Test_vartabs_linebreak()
if winwidth(0) < 40
return
endif
@@ -296,3 +296,14 @@ func! Test_vartabs_linebreak()
bw!
set nolist listchars&vim
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