Patch 9.0.1307
Problem:    Setting 'formatoptions' with :let doesn't check for errors.
Solution:   Pass "errbuf" to set_string_option(). (Yegappan Lakshmanan,
            closes #11974, closes #11972)
Files:      src/option.c, src/optionstr.c, src/proto/optionstr.pro,
            src/testdir/test_options.vim


*** ../vim-9.0.1306/src/option.c        2023-02-10 14:50:27.498918636 +0000
--- src/option.c        2023-02-13 15:57:12.007241555 +0000
***************
*** 5135,5140 ****
--- 5135,5141 ----
      int               opt_idx;
      char_u    *varp;
      long_u    flags;
+     static char       errbuf[80];
  
      opt_idx = findoption(name);
      if (opt_idx < 0)
***************
*** 5177,5183 ****
        }
  #endif
        if (flags & P_STRING)
!           return set_string_option(opt_idx, string, opt_flags);
  
        varp = get_varp_scope(&(options[opt_idx]), opt_flags);
        if (varp != NULL)       // hidden option is not changed
--- 5178,5184 ----
        }
  #endif
        if (flags & P_STRING)
!           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,5209 ****
                }
            }
            if (flags & P_NUM)
                return set_num_option(opt_idx, varp, number,
!                                                          NULL, 0, opt_flags);
            else
                return set_bool_option(opt_idx, varp, (int)number, opt_flags);
        }
--- 5203,5212 ----
                }
            }
            if (flags & P_NUM)
+           {
                return set_num_option(opt_idx, varp, number,
!                                          errbuf, sizeof(errbuf), opt_flags);
!           }
            else
                return set_bool_option(opt_idx, varp, (int)number, opt_flags);
        }
*** ../vim-9.0.1306/src/optionstr.c     2023-02-11 11:15:19.999085252 +0000
--- src/optionstr.c     2023-02-13 15:57:12.007241555 +0000
***************
*** 487,493 ****
  set_string_option(
      int               opt_idx,
      char_u    *value,
!     int               opt_flags)      // OPT_LOCAL and/or OPT_GLOBAL
  {
      char_u    *s;
      char_u    **varp;
--- 487,494 ----
  set_string_option(
      int               opt_idx,
      char_u    *value,
!     int               opt_flags,      // OPT_LOCAL and/or OPT_GLOBAL
!     char      *errbuf)
  {
      char_u    *s;
      char_u    **varp;
***************
*** 540,546 ****
        saved_newval = vim_strsave(s);
      }
  #endif
!     if ((errmsg = did_set_string_option(opt_idx, varp, oldval, NULL,
                    opt_flags, &value_checked)) == NULL)
        did_set_option(opt_idx, opt_flags, TRUE, value_checked);
  
--- 541,547 ----
        saved_newval = vim_strsave(s);
      }
  #endif
!     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);
  
*** ../vim-9.0.1306/src/proto/optionstr.pro     2022-12-16 16:41:19.208714806 
+0000
--- src/proto/optionstr.pro     2023-02-13 16:09:21.763542213 +0000
***************
*** 8,14 ****
  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 *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);
--- 8,14 ----
  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 
*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);
*** ../vim-9.0.1306/src/testdir/test_options.vim        2022-11-12 
11:54:19.205571527 +0000
--- src/testdir/test_options.vim        2023-02-13 16:08:48.159532946 +0000
***************
*** 483,488 ****
--- 483,490 ----
    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,1469 ****
--- 1467,1509 ----
    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
*** ../vim-9.0.1306/src/version.c       2023-02-12 18:11:03.678422979 +0000
--- src/version.c       2023-02-13 15:58:57.715204107 +0000
***************
*** 697,698 ****
--- 697,700 ----
  {   /* Add new patch number below this line */
+ /**/
+     1307,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
120. You ask a friend, "What's that big shiny thing?" He says, "It's the sun."

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20230213161031.AB3171C0830%40moolenaar.net.

Raspunde prin e-mail lui