changeset 19966:c0eb073378e7 v8.2.0539

patch 8.2.0539: comparing two NULL list fails Commit: https://github.com/vim/vim/commit/7b293c730b07d1586688e622b8d9cbbb4a52379b Author: Bram Moolenaar <Bram@vim.org> Date: Thu Apr 9 21:33:22 2020 +0200 patch 8.2.0539: comparing two NULL list fails Problem: Comparing two NULL list fails. Solution: Change the order of comparing two lists.
author Bram Moolenaar <Bram@vim.org>
date Thu, 09 Apr 2020 21:45:03 +0200
parents 98fb36b068e4
children f11b9ed4f9e1
files src/list.c src/testdir/test_assert.vim src/version.c
diffstat 3 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/list.c
+++ b/src/list.c
@@ -368,12 +368,15 @@ list_equal(
 {
     listitem_T	*item1, *item2;
 
-    if (l1 == NULL || l2 == NULL)
-	return FALSE;
     if (l1 == l2)
 	return TRUE;
     if (list_len(l1) != list_len(l2))
 	return FALSE;
+    if (list_len(l1) == 0)
+	// empty and NULL list are considered equal
+	return TRUE;
+    if (l1 == NULL || l2 == NULL)
+	return FALSE;
 
     range_list_materialize(l1);
     range_list_materialize(l2);
--- a/src/testdir/test_assert.vim
+++ b/src/testdir/test_assert.vim
@@ -36,6 +36,9 @@ func Test_assert_equal()
   call assert_equal(0, assert_equal(4, n))
   let l = [1, 2, 3]
   call assert_equal(0, assert_equal([1, 2, 3], l))
+  call assert_equal(test_null_list(), test_null_list())
+  call assert_equal(test_null_list(), [])
+  call assert_equal([], test_null_list())
 
   let s = 'foo'
   call assert_equal(1, assert_equal('bar', s))
--- a/src/version.c
+++ b/src/version.c
@@ -739,6 +739,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    539,
+/**/
     538,
 /**/
     537,