Patch 8.2.3545
Problem:    setcellwidths() may make 'listchars' or 'fillchars' invalid.
Solution:   Check the value and give an error. (closes #9024)
Files:      runtime/doc/eval.txt, src/optionstr.c, src/errors.h, src/mbyte.c,
            src/testdir/test_utf8.vim


*** ../vim-8.2.3544/runtime/doc/eval.txt        2021-10-14 21:27:50.642253782 
+0100
--- runtime/doc/eval.txt        2021-10-20 10:47:30.116748341 +0100
***************
*** 9551,9556 ****
--- 9648,9656 ----
                range overlaps with another.
                Only characters with value 0x100 and higher can be used.
  
+               If the new value causes 'fillchars' or 'listchars' to become
+               invalid it is rejected and an error is given.
+ 
                To clear the overrides pass an empty list: >
                   setcellwidths([]);
  <             You can use the script $VIMRUNTIME/tools/emoji_list.vim to see
*** ../vim-8.2.3544/src/optionstr.c     2021-10-16 21:14:07.495196461 +0100
--- src/optionstr.c     2021-10-20 10:53:00.977185556 +0100
***************
*** 871,877 ****
        if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
            errmsg = e_invarg;
        else if (set_chars_option(curwin, &p_fcs) != NULL)
!           errmsg = _("E835: Conflicts with value of 'fillchars'");
        else
        {
            tabpage_T   *tp;
--- 871,877 ----
        if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
            errmsg = e_invarg;
        else if (set_chars_option(curwin, &p_fcs) != NULL)
!           errmsg = _(e_conflicts_with_value_of_fillchars);
        else
        {
            tabpage_T   *tp;
***************
*** 881,887 ****
            {
                if (set_chars_option(wp, &wp->w_p_lcs) != NULL)
                {
!                   errmsg = _("E834: Conflicts with value of 'listchars'");
                    goto ambw_end;
                }
            }
--- 881,887 ----
            {
                if (set_chars_option(wp, &wp->w_p_lcs) != NULL)
                {
!                   errmsg = _(e_conflicts_with_value_of_listchars);
                    goto ambw_end;
                }
            }
*** ../vim-8.2.3544/src/errors.h        2021-10-16 20:52:01.772842109 +0100
--- src/errors.h        2021-10-20 10:52:36.172842449 +0100
***************
*** 160,165 ****
--- 160,169 ----
        INIT(= N_("E711: List value does not have enough items"));
  EXTERN char e_cannot_slice_dictionary[]
        INIT(= N_("E719: Cannot slice a Dictionary"));
+ EXTERN char e_conflicts_with_value_of_listchars[]
+       INIT(= N_("E834: Conflicts with value of 'listchars'"));
+ EXTERN char e_conflicts_with_value_of_fillchars[]
+       INIT(= N_("E835: Conflicts with value of 'fillchars'"));
  EXTERN char e_assert_fails_second_arg[]
        INIT(= N_("E856: \"assert_fails()\" second argument must be a string or 
a list with one or two strings"));
  EXTERN char e_using_invalid_value_as_string_str[]
*** ../vim-8.2.3544/src/mbyte.c 2021-07-27 21:00:39.749712387 +0100
--- src/mbyte.c 2021-10-20 10:55:42.335447327 +0100
***************
*** 5510,5515 ****
--- 5510,5517 ----
      int                   i;
      listitem_T            **ptrs;
      cw_interval_T   *table;
+     cw_interval_T   *cw_table_save;
+     size_t        cw_table_size_save;
  
      if (in_vim9script() && check_for_list_arg(argvars, 0) == FAIL)
        return;
***************
*** 5620,5628 ****
      }
  
      vim_free(ptrs);
!     vim_free(cw_table);
      cw_table = table;
      cw_table_size = l->lv_len;
  }
  
      void
--- 5622,5662 ----
      }
  
      vim_free(ptrs);
! 
!     cw_table_save = cw_table;
!     cw_table_size_save = cw_table_size;
      cw_table = table;
      cw_table_size = l->lv_len;
+ 
+     // Check that the new value does not conflict with 'fillchars' or
+     // 'listchars'.
+     if (set_chars_option(curwin, &p_fcs) != NULL)
+     {
+       emsg(_(e_conflicts_with_value_of_fillchars));
+       cw_table = cw_table_save;
+       cw_table_size = cw_table_size_save;
+       vim_free(table);
+       return;
+     }
+     else
+     {
+       tabpage_T       *tp;
+       win_T   *wp;
+ 
+       FOR_ALL_TAB_WINDOWS(tp, wp)
+       {
+           if (set_chars_option(wp, &wp->w_p_lcs) != NULL)
+           {
+               emsg((e_conflicts_with_value_of_listchars));
+               cw_table = cw_table_save;
+               cw_table_size = cw_table_size_save;
+               vim_free(table);
+               return;
+           }
+       }
+     }
+ 
+     vim_free(cw_table_save);
  }
  
      void
*** ../vim-8.2.3544/src/testdir/test_utf8.vim   2021-03-14 18:01:34.496421810 
+0000
--- src/testdir/test_utf8.vim   2021-10-20 10:53:13.405357974 +0100
***************
*** 185,190 ****
--- 185,200 ----
    call assert_fails('call setcellwidths([[0x111, 0x122, 1], [0x122, 0x123, 
2]])', 'E1113:')
  
    call assert_fails('call setcellwidths([[0x33, 0x44, 2]])', 'E1114:')
+ 
+   set listchars=tab:--\\u2192
+   call assert_fails('call setcellwidths([[0x2192, 0x2192, 2]])', 'E834:')
+ 
+   set fillchars=stl:\\u2501
+   call assert_fails('call setcellwidths([[0x2501, 0x2501, 2]])', 'E835:')
+ 
+   set listchars&
+   set fillchars&
+   call setcellwidths([])
  endfunc
  
  func Test_print_overlong()
*** ../vim-8.2.3544/src/version.c       2021-10-20 10:00:01.278269544 +0100
--- src/version.c       2021-10-20 10:57:19.612831645 +0100
***************
*** 759,760 ****
--- 759,762 ----
  {   /* Add new patch number below this line */
+ /**/
+     3545,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
206. You religiously respond immediately to e-mail, while ignoring
     your growing pile of snail mail.

 /// 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/20211020100150.DC7D0C80053%40moolenaar.net.

Raspunde prin e-mail lui