changeset 33821:6c92d6f3a255 v9.0.2126

patch 9.0.2126: unused assignments when checking 'listchars' Commit: https://github.com/vim/vim/commit/00624a2fa08d04bdded240d474e9cfdc193dbe10 Author: zeertzjq <zeertzjq@outlook.com> Date: Thu Nov 23 20:47:16 2023 +0100 patch 9.0.2126: unused assignments when checking 'listchars' Problem: Unused assignments when checking the value of 'listchars'. Solution: Loop only once when just checking the value. Add a test to check that this change doesn't cause double-free. closes: #13559 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Thu, 23 Nov 2023 21:00:04 +0100
parents 83aac5eb0612
children abd7434511dc
files src/screen.c src/testdir/test_listchars.vim src/version.c
diffstat 3 files changed, 8 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/screen.c
+++ b/src/screen.c
@@ -4726,7 +4726,7 @@ set_chars_option(win_T *wp, char_u *valu
     }
 
     // first round: check for valid value, second round: assign values
-    for (round = 0; round <= 1; ++round)
+    for (round = 0; round <= (apply ? 1 : 0); ++round)
     {
 	if (round > 0)
 	{
@@ -4913,11 +4913,6 @@ set_chars_option(win_T *wp, char_u *valu
 	    wp->w_fill_chars = fill_chars;
 	}
     }
-    else if (is_listchars)
-    {
-	vim_free(lcs_chars.multispace);
-	vim_free(lcs_chars.leadmultispace);
-    }
 
     return NULL;	// no error
 }
--- a/src/testdir/test_listchars.vim
+++ b/src/testdir/test_listchars.vim
@@ -265,6 +265,11 @@ func Test_listchars()
   call Check_listchars(expected, 5, 12)
   call assert_equal(expected, split(execute("%list"), "\n"))
 
+  " Changing the value of 'ambiwidth' twice shouldn't cause double-free when
+  " "leadmultispace" is specified.
+  set ambiwidth=double
+  set ambiwidth&
+
   " Test leadmultispace and lead and space
   normal ggdG
   set listchars&
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2126,
+/**/
     2125,
 /**/
     2124,