changeset 31950:b0717fcca5eb v9.0.1307

patch 9.0.1307: setting 'formatoptions' with :let doesn't check for errors Commit: https://github.com/vim/vim/commit/32ff96ef018eb1a5bea0953648b4892a6ee71658 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Mon Feb 13 16:10:04 2023 +0000 patch 9.0.1307: setting 'formatoptions' with :let doesn't check for errors Problem: Setting 'formatoptions' with :let doesn't check for errors. Solution: Pass "errbuf" to set_string_option(). (Yegappan Lakshmanan, closes #11974, closes #11972)
author Bram Moolenaar <Bram@vim.org>
date Mon, 13 Feb 2023 17:15:04 +0100
parents 490cc052f7d9
children d471b7bc05a2
files src/option.c src/optionstr.c src/proto/optionstr.pro src/testdir/test_options.vim src/version.c
diffstat 5 files changed, 51 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/option.c
+++ b/src/option.c
@@ -5135,6 +5135,7 @@ set_option_value(
     int		opt_idx;
     char_u	*varp;
     long_u	flags;
+    static char	errbuf[80];
 
     opt_idx = findoption(name);
     if (opt_idx < 0)
@@ -5177,7 +5178,7 @@ set_option_value(
 	}
 #endif
 	if (flags & P_STRING)
-	    return set_string_option(opt_idx, string, opt_flags);
+	    return set_string_option(opt_idx, string, opt_flags, errbuf);
 
 	varp = get_varp_scope(&(options[opt_idx]), opt_flags);
 	if (varp != NULL)	// hidden option is not changed
@@ -5202,8 +5203,10 @@ set_option_value(
 		}
 	    }
 	    if (flags & P_NUM)
+	    {
 		return set_num_option(opt_idx, varp, number,
-							   NULL, 0, opt_flags);
+					   errbuf, sizeof(errbuf), opt_flags);
+	    }
 	    else
 		return set_bool_option(opt_idx, varp, (int)number, opt_flags);
 	}
--- a/src/optionstr.c
+++ b/src/optionstr.c
@@ -487,7 +487,8 @@ set_string_option_direct_in_buf(
 set_string_option(
     int		opt_idx,
     char_u	*value,
-    int		opt_flags)	// OPT_LOCAL and/or OPT_GLOBAL
+    int		opt_flags,	// OPT_LOCAL and/or OPT_GLOBAL
+    char	*errbuf)
 {
     char_u	*s;
     char_u	**varp;
@@ -540,7 +541,7 @@ set_string_option(
 	saved_newval = vim_strsave(s);
     }
 #endif
-    if ((errmsg = did_set_string_option(opt_idx, varp, oldval, NULL,
+    if ((errmsg = did_set_string_option(opt_idx, varp, oldval, errbuf,
 		    opt_flags, &value_checked)) == NULL)
 	did_set_option(opt_idx, opt_flags, TRUE, value_checked);
 
--- a/src/proto/optionstr.pro
+++ b/src/proto/optionstr.pro
@@ -8,7 +8,7 @@ void check_string_option(char_u **pp);
 void set_string_option_direct(char_u *name, int opt_idx, char_u *val, int opt_flags, int set_sid);
 void set_string_option_direct_in_win(win_T *wp, char_u *name, int opt_idx, char_u *val, int opt_flags, int set_sid);
 void set_string_option_direct_in_buf(buf_T *buf, char_u *name, int opt_idx, char_u *val, int opt_flags, int set_sid);
-char *set_string_option(int opt_idx, char_u *value, int opt_flags);
+char *set_string_option(int opt_idx, char_u *value, int opt_flags, char *errbuf);
 char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *errbuf, int opt_flags, int *value_checked);
 int check_ff_value(char_u *p);
 void save_clear_shm_value(void);
--- a/src/testdir/test_options.vim
+++ b/src/testdir/test_options.vim
@@ -483,6 +483,8 @@ func Test_set_errors()
   call assert_fails('set fileencoding=latin1', 'E21:')
   set modifiable&
   call assert_fails('set t_#-&', 'E522:')
+  call assert_fails('let &formatoptions = "?"', 'E539:')
+  call assert_fails('call setbufvar("", "&formatoptions", "?")', 'E539:')
 endfunc
 
 func Test_set_encoding()
@@ -1465,5 +1467,43 @@ func Test_endoffile_default()
   call delete('Xtestout')
 endfunc
 
+" Test for setting the 'lines' and 'columns' options to a minimum value
+func Test_set_min_lines_columns()
+  let save_lines = &lines
+  let save_columns = &columns
+
+  let after =<< trim END
+    set nomore
+    let msg = []
+    let v:errmsg = ''
+    silent! let &columns=0
+    call add(msg, v:errmsg)
+    silent! set columns=0
+    call add(msg, v:errmsg)
+    silent! call setbufvar('', '&columns', 0)
+    call add(msg, v:errmsg)
+    "call writefile(msg, 'XResultsetminlines')
+    silent! let &lines=0
+    call add(msg, v:errmsg)
+    silent! set lines=0
+    call add(msg, v:errmsg)
+    silent! call setbufvar('', '&lines', 0)
+    call add(msg, v:errmsg)
+    call writefile(msg, 'XResultsetminlines')
+    qall!
+  END
+  if RunVim([], after, '')
+    call assert_equal(['E594: Need at least 12 columns',
+          \ 'E594: Need at least 12 columns: columns=0',
+          \ 'E594: Need at least 12 columns',
+          \ 'E593: Need at least 2 lines',
+          \ 'E593: Need at least 2 lines: lines=0',
+          \ 'E593: Need at least 2 lines',], readfile('XResultsetminlines'))
+  endif
+
+  call delete('XResultsetminlines')
+  let &lines = save_lines
+  let &columns = save_columns
+endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1307,
+/**/
     1306,
 /**/
     1305,