]> granicus.if.org Git - vim/commitdiff
patch 9.0.1307: setting 'formatoptions' with :let doesn't check for errors v9.0.1307
authorYegappan Lakshmanan <yegappan@yahoo.com>
Mon, 13 Feb 2023 16:10:04 +0000 (16:10 +0000)
committerBram Moolenaar <Bram@vim.org>
Mon, 13 Feb 2023 16:10:04 +0000 (16:10 +0000)
Problem:    Setting 'formatoptions' with :let doesn't check for errors.
Solution:   Pass "errbuf" to set_string_option(). (Yegappan Lakshmanan,
            closes #11974, closes #11972)

src/option.c
src/optionstr.c
src/proto/optionstr.pro
src/testdir/test_options.vim
src/version.c

index ee9c9e33bab5aa4e781dc091e5ac1e435d8fa297..c2f0028671a7658f8be154f8f993f317a13a2307 100644 (file)
@@ -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);
        }
index 7dfb7b7ff58f3719d6f9c21303cbd94fd4adb433..6c9fd3ab32cbce9e107e3e04b1e542151fbc1a14 100644 (file)
@@ -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);
 
index e75e3dcdb7826826b2f1ef055f21b175f7d65385..d4f96be40caabeb651766a121baaa82e7841ad7c 100644 (file)
@@ -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);
index 30828e2da843363d17788f43b567a6c9e2e75dd6..ff8372786a3a4fda15686174a6ee6ed172f0b9cf 100644 (file)
@@ -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
index f3877e429bd3bddb23b8d838e904304959029f2c..ee9bf28665dff818a98f6fd4fed5252455fd894e 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1307,
 /**/
     1306,
 /**/