Patch 9.0.0204
Problem:    indexof() may leak memory.
Solution:   Free allocated values. (Yegappan Lakshmanan, closes #10916)
Files:      src/evalfunc.c, src/testdir/test_blob.vim,
            src/testdir/test_listdict.vim, src/testdir/test_vim9_builtin.vim


*** ../vim-9.0.0203/src/evalfunc.c      2022-08-13 21:34:18.999400776 +0100
--- src/evalfunc.c      2022-08-14 12:02:29.634980261 +0100
***************
*** 6814,6819 ****
--- 6814,6820 ----
        return FALSE;
  
      found = tv_get_bool_chk(&newtv, &error);
+     clear_tv(&newtv);
  
      return error ? FALSE : found;
  }
***************
*** 6864,6869 ****
--- 6865,6871 ----
  {
      listitem_T        *item;
      long      idx = 0;
+     int               found;
  
      if (l == NULL)
        return -1;
***************
*** 6888,6894 ****
        set_vim_var_nr(VV_KEY, idx);
        copy_tv(&item->li_tv, get_vim_var_tv(VV_VAL));
  
!       if (indexof_eval_expr(expr))
            return idx;
      }
  
--- 6890,6899 ----
        set_vim_var_nr(VV_KEY, idx);
        copy_tv(&item->li_tv, get_vim_var_tv(VV_VAL));
  
!       found = indexof_eval_expr(expr);
!       clear_tv(get_vim_var_tv(VV_VAL));
! 
!       if (found)
            return idx;
      }
  
*** ../vim-9.0.0203/src/testdir/test_blob.vim   2022-08-13 13:08:30.286914784 
+0100
--- src/testdir/test_blob.vim   2022-08-14 12:02:29.634980261 +0100
***************
*** 772,777 ****
--- 772,778 ----
    call assert_equal(-1, indexof(b, {i, v -> v == 0x1}))
    call assert_equal(1, indexof(b, "v:val == 0xad"))
    call assert_equal(-1, indexof(b, "v:val == 0xff"))
+   call assert_equal(-1, indexof(b, {_, v -> "v == 0xad"}))
  
    call assert_equal(-1, indexof(0z, "v:val == 0x0"))
    call assert_equal(-1, indexof(test_null_blob(), "v:val == 0xde"))
*** ../vim-9.0.0203/src/testdir/test_listdict.vim       2022-08-13 
13:08:30.286914784 +0100
--- src/testdir/test_listdict.vim       2022-08-14 12:02:29.634980261 +0100
***************
*** 1462,1468 ****
--- 1462,1474 ----
    call assert_equal(-1, indexof(l, "v:val.n == 10", #{startidx: -4}))
    call assert_equal(0, indexof(l, "v:val.n == 10", test_null_dict()))
  
+   let s = ["a", "b", "c"]
+   call assert_equal(2, indexof(s, {_, v -> v == 'c'}))
+   call assert_equal(-1, indexof(s, {_, v -> v == 'd'}))
+   call assert_equal(-1, indexof(s, {_, v -> "v == 'd'"}))
+ 
    call assert_equal(-1, indexof([], {i, v -> v == 'a'}))
+   call assert_equal(-1, indexof([1, 2, 3], {_, v -> "v == 2"}))
    call assert_equal(-1, indexof(test_null_list(), {i, v -> v == 'a'}))
    call assert_equal(-1, indexof(l, test_null_string()))
    call assert_equal(-1, indexof(l, test_null_function()))
*** ../vim-9.0.0203/src/testdir/test_vim9_builtin.vim   2022-08-13 
21:34:18.999400776 +0100
--- src/testdir/test_vim9_builtin.vim   2022-08-14 12:02:29.634980261 +0100
***************
*** 2074,2083 ****
    var b = 0zdeadbeef
    indexof(b, "v:val == 0xef")->assert_equal(3)
  
!   def TestIdx(k: number, v: dict<any>): bool
      return v.color == 'blue'
    enddef
!   indexof(l, TestIdx)->assert_equal(1)
  enddef
  
  def Test_input()
--- 2074,2109 ----
    var b = 0zdeadbeef
    indexof(b, "v:val == 0xef")->assert_equal(3)
  
!   def TestIdx1(k: number, v: dict<any>): bool
      return v.color == 'blue'
    enddef
!   indexof(l, TestIdx1)->assert_equal(1)
! 
!   var lines =<< trim END
!     def TestIdx(v: dict<any>): bool
!       return v.color == 'blue'
!     enddef
! 
!     indexof([{color: "red"}], TestIdx)
!   END
!   v9.CheckDefAndScriptFailure(lines, ['E176: Invalid number of arguments', 
'E118: Too many arguments for function'])
! 
!   lines =<< trim END
!     def TestIdx(k: number, v: dict<any>)
!     enddef
! 
!     indexof([{color: "red"}], TestIdx)
!   END
!   v9.CheckDefAndScriptFailure(lines, ['E1013: Argument 2: type mismatch, 
expected func(?number, ?any): bool', 'E1031: Cannot use void value'])
! 
!   lines =<< trim END
!     def TestIdx(k: number, v: dict<any>): string
!       return "abc"
!     enddef
! 
!     indexof([{color: "red"}], TestIdx)
!   END
!   v9.CheckDefAndScriptFailure(lines, ['E1013: Argument 2: type mismatch, 
expected func(?number, ?any): bool', 'E1135: Using a String as a Bool'])
  enddef
  
  def Test_input()
*** ../vim-9.0.0203/src/version.c       2022-08-13 21:37:24.955160678 +0100
--- src/version.c       2022-08-14 12:03:33.830951260 +0100
***************
*** 737,738 ****
--- 737,740 ----
  {   /* Add new patch number below this line */
+ /**/
+     204,
  /**/

-- 
LAUNCELOT: At last!   A call!  A cry of distress ...
           (he draws his sword, and turns to CONCORDE)
           Concorde!  Brave, Concorde ... you shall not have died in vain!
CONCORDE:  I'm not quite dead, sir ...
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// 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/20220814123013.CDFD71C0CD2%40moolenaar.net.

Raspunde prin e-mail lui