Patch 8.2.1537
Problem:    Memory acccess error when using setcellwidths().
Solution:   Use array and pointers correctly.
Files:      src/mbyte.c, src/errors.h, src/testdir/test_utf8.vim


*** ../vim-8.2.1536/src/mbyte.c 2020-08-28 22:24:40.660494318 +0200
--- src/mbyte.c 2020-08-28 23:26:02.829350331 +0200
***************
*** 5421,5428 ****
      static int
  tv_nr_compare(const void *a1, const void *a2)
  {
!     listitem_T *li1 = (listitem_T *)a1;
!     listitem_T *li2 = (listitem_T *)a2;
  
      return li1->li_tv.vval.v_number - li2->li_tv.vval.v_number;
  }
--- 5421,5428 ----
      static int
  tv_nr_compare(const void *a1, const void *a2)
  {
!     listitem_T *li1 = *(listitem_T **)a1;
!     listitem_T *li2 = *(listitem_T **)a2;
  
      return li1->li_tv.vval.v_number - li2->li_tv.vval.v_number;
  }
***************
*** 5470,5477 ****
            vim_free(ptrs);
            return;
        }
!       for (lili = li->li_tv.vval.v_list->lv_first, i = 0; lili != NULL;
!                                                    lili = lili->li_next, ++i)
        {
            if (lili->li_tv.v_type != VAR_NUMBER)
                break;
--- 5470,5479 ----
            vim_free(ptrs);
            return;
        }
! 
!       lili = li->li_tv.vval.v_list->lv_first;
!       ptrs[item] = lili;
!       for (i = 0; lili != NULL; lili = lili->li_next, ++i)
        {
            if (lili->li_tv.v_type != VAR_NUMBER)
                break;
***************
*** 5505,5511 ****
            vim_free(ptrs);
            return;
        }
!       ptrs[item++] = lili;
      }
  
      // Sort the list on the first number.
--- 5507,5513 ----
            vim_free(ptrs);
            return;
        }
!       ++item;
      }
  
      // Sort the list on the first number.
***************
*** 5520,5528 ****
  
      // Store the items in the new table.
      item = 0;
!     for (li = l->lv_first; li != NULL; li = li->li_next)
      {
!       listitem_T      *lili = li->li_tv.vval.v_list->lv_first;
        varnumber_T     n1;
  
        n1 = lili->li_tv.vval.v_number;
--- 5522,5530 ----
  
      // Store the items in the new table.
      item = 0;
!     for (item = 0; item < l->lv_len; ++item)
      {
!       listitem_T      *lili = ptrs[item];
        varnumber_T     n1;
  
        n1 = lili->li_tv.vval.v_number;
***************
*** 5538,5544 ****
        table[item].last = lili->li_tv.vval.v_number;
        lili = lili->li_next;
        table[item].width = lili->li_tv.vval.v_number;
-       ++item;
      }
  
      vim_free(ptrs);
--- 5540,5545 ----
*** ../vim-8.2.1536/src/errors.h        2020-08-28 21:04:20.502881357 +0200
--- src/errors.h        2020-08-28 23:24:50.869779174 +0200
***************
*** 247,253 ****
  EXTERN char e_list_item_nr_cell_width_invalid[]
        INIT(= N_("E1112: List item %d cell width invalid"));
  EXTERN char e_overlapping_ranges_for_nr[]
!       INIT(= N_("E1113: Overlapping ranges for %lx"));
  EXTERN char e_only_values_of_0x100_and_higher_supported[]
        INIT(= N_("E1114: Only values of 0x100 and higher supported"));
  #endif
--- 247,253 ----
  EXTERN char e_list_item_nr_cell_width_invalid[]
        INIT(= N_("E1112: List item %d cell width invalid"));
  EXTERN char e_overlapping_ranges_for_nr[]
!       INIT(= N_("E1113: Overlapping ranges for 0x%lx"));
  EXTERN char e_only_values_of_0x100_and_higher_supported[]
        INIT(= N_("E1114: Only values of 0x100 and higher supported"));
  #endif
*** ../vim-8.2.1536/src/testdir/test_utf8.vim   2020-08-28 21:04:20.502881357 
+0200
--- src/testdir/test_utf8.vim   2020-08-28 23:15:05.860323641 +0200
***************
*** 148,155 ****
  func Test_setcellwidths()
    call setcellwidths([
          \ [0x1330, 0x1330, 2],
-         \ [0x1337, 0x1339, 2],
          \ [9999, 10000, 1],
          \])
  
    call assert_equal(2, strwidth("\u1330"))
--- 148,155 ----
  func Test_setcellwidths()
    call setcellwidths([
          \ [0x1330, 0x1330, 2],
          \ [9999, 10000, 1],
+         \ [0x1337, 0x1339, 2],
          \])
  
    call assert_equal(2, strwidth("\u1330"))
*** ../vim-8.2.1536/src/version.c       2020-08-28 22:24:40.660494318 +0200
--- src/version.c       2020-08-28 23:14:43.844414297 +0200
***************
*** 756,757 ****
--- 756,759 ----
  {   /* Add new patch number below this line */
+ /**/
+     1537,
  /**/

-- 
A successful man is one who makes more money than his wife can spend.
A successful woman is one who can find such a man.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            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/202008282127.07SLRlH32364329%40masaka.moolenaar.net.

Raspunde prin e-mail lui