patch 8.2.3545: setcellwidths() may make 'listchars' or 'fillchars' invalid

Problem:    setcellwidths() may make 'listchars' or 'fillchars' invalid.
Solution:   Check the value and give an error. (closes #9024)
diff --git a/src/errors.h b/src/errors.h
index 12d00b7..96a9b2f 100644
--- a/src/errors.h
+++ b/src/errors.h
@@ -160,6 +160,10 @@
 	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[]
diff --git a/src/mbyte.c b/src/mbyte.c
index a626f50..76eab4e 100644
--- a/src/mbyte.c
+++ b/src/mbyte.c
@@ -5510,6 +5510,8 @@
     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,9 +5622,41 @@
     }
 
     vim_free(ptrs);
-    vim_free(cw_table);
+
+    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
diff --git a/src/optionstr.c b/src/optionstr.c
index 7f2b04d..3afb3db 100644
--- a/src/optionstr.c
+++ b/src/optionstr.c
@@ -871,7 +871,7 @@
 	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'");
+	    errmsg = _(e_conflicts_with_value_of_fillchars);
 	else
 	{
 	    tabpage_T	*tp;
@@ -881,7 +881,7 @@
 	    {
 		if (set_chars_option(wp, &wp->w_p_lcs) != NULL)
 		{
-		    errmsg = _("E834: Conflicts with value of 'listchars'");
+		    errmsg = _(e_conflicts_with_value_of_listchars);
 		    goto ambw_end;
 		}
 	    }
diff --git a/src/testdir/test_utf8.vim b/src/testdir/test_utf8.vim
index 5454e43..250df0b 100644
--- a/src/testdir/test_utf8.vim
+++ b/src/testdir/test_utf8.vim
@@ -185,6 +185,16 @@
   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()
diff --git a/src/version.c b/src/version.c
index 227db82..072d11f 100644
--- a/src/version.c
+++ b/src/version.c
@@ -758,6 +758,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    3545,
+/**/
     3544,
 /**/
     3543,