Patch 8.2.4528

12 views
Skip to first unread message

Bram Moolenaar

unread,
Mar 8, 2022, 11:53:48 AM3/8/22
to vim...@googlegroups.com

Patch 8.2.4528
Problem: Crash when using null_function for a partial.
Solution: Don't call fname_trans_sid() with NULL. (closes #9908)
Files: src/userfunc.c, src/testdir/test_vim9_func.vim


*** ../vim-8.2.4527/src/userfunc.c 2022-03-05 20:24:36.899308689 +0000
--- src/userfunc.c 2022-03-08 16:49:15.880077033 +0000
***************
*** 5730,5736 ****
make_partial(dict_T *selfdict_in, typval_T *rettv)
{
char_u *fname;
- char_u *tofree = NULL;
ufunc_T *fp;
char_u fname_buf[FLEN_FIXED + 1];
int error;
--- 5730,5735 ----
***************
*** 5742,5754 ****
{
fname = rettv->v_type == VAR_FUNC ? rettv->vval.v_string
: rettv->vval.v_partial->pt_name;
! // Translate "s:func" to the stored function name.
! fname = fname_trans_sid(fname, fname_buf, &tofree, &error);
! fp = find_func(fname, FALSE);
! vim_free(tofree);
}

! if (fp != NULL && (fp->uf_flags & FC_DICT))
{
partial_T *pt = ALLOC_CLEAR_ONE(partial_T);

--- 5741,5759 ----
{
fname = rettv->v_type == VAR_FUNC ? rettv->vval.v_string
: rettv->vval.v_partial->pt_name;
! if (fname != NULL)
! {
! char_u *tofree = NULL;
!
! // Translate "s:func" to the stored function name.
! fname = fname_trans_sid(fname, fname_buf, &tofree, &error);
! fp = find_func(fname, FALSE);
! vim_free(tofree);
! }
}

! if ((fp != NULL && (fp->uf_flags & FC_DICT))
! || (rettv->v_type == VAR_FUNC && rettv->vval.v_string == NULL))
{
partial_T *pt = ALLOC_CLEAR_ONE(partial_T);

*** ../vim-8.2.4527/src/testdir/test_vim9_func.vim 2022-03-08 13:18:10.813020777 +0000
--- src/testdir/test_vim9_func.vim 2022-03-08 16:51:18.819893096 +0000
***************
*** 3337,3342 ****
--- 3337,3351 ----
assert_equal(123, RefRef())
enddef

+ def Test_partial_null_function()
+ var lines =<< trim END
+ var d: dict<func> = {f: null_function}
+ var Ref = d.f
+ assert_equal('func', typename(Ref))
+ END
+ v9.CheckDefAndScriptSuccess(lines)
+ enddef
+
" Using "idx" from a legacy global function does not work.
" This caused a crash when called from legacy context.
func Test_partial_call_fails()
*** ../vim-8.2.4527/src/version.c 2022-03-08 13:32:34.238804971 +0000
--- src/version.c 2022-03-08 16:49:01.424096580 +0000
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 4528,
/**/

--
panic("Foooooooood fight!");
-- In the kernel source aha1542.c, after detecting a bad segment list

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

John Marriott

unread,
Mar 8, 2022, 1:31:57 PM3/8/22
to vim...@googlegroups.com

On 09-Mar-2022 03:53, Bram Moolenaar wrote:
> Patch 8.2.4528
> Problem: Crash when using null_function for a partial.
> Solution: Don't call fname_trans_sid() with NULL. (closes #9908)
> Files: src/userfunc.c, src/testdir/test_vim9_func.vim
>
>
After this patch, mingw64 (gcc 11.2.0) throws this warning:
<snip>
gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
-DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -D__USE_MINGW_ANSI_STDIO
-pipe -march=native -Wall -O3 -fomit-frame-pointer -freg-struct-return
-fpie -fPIE -DFEAT_GUI_MSWIN -DFEAT_CLIPBOARD userfunc.c -o
gobjnative/userfunc.o
userfunc.c: In function 'make_partial':
userfunc.c:5755:27: warning: 'fp' may be used uninitialized in this
function [-Wmaybe-uninitialized]
 5755 |     if ((fp != NULL && (fp->uf_flags & FC_DICT))
      |                         ~~^~~~~~~~~~
</snip>

The attached patch tries to fix it.

Cheers
John
userfunc.c.8.2.4528.patch

Bram Moolenaar

unread,
Mar 8, 2022, 4:37:45 PM3/8/22
to vim...@googlegroups.com, John Marriott
It actually caused a crash, when I was adding a few more tests.
The fix has been included with 8.2.4529.

--
hundred-and-one symptoms of being an internet addict:
208. Your goals for the future are obtaining a second Gbit connection
and upgrade your NAS to all SSD
Reply all
Reply to author
Forward
0 new messages