# HG changeset patch # User Bram Moolenaar # Date 1651264203 -7200 # Node ID a2cf17d0d5da915da45032ec84d59fdb1a472b76 # Parent a9eca6be0c8cd7fade67fb5512866d36a3d65c9e patch 8.2.4847: crash when using uninitialized function pointer Commit: https://github.com/vim/vim/commit/a5d3590505fc3e1deea990560d472baa563abed7 Author: LemonBoy Date: Fri Apr 29 21:15:02 2022 +0100 patch 8.2.4847: crash when using uninitialized function pointer Problem: Crash when using uninitialized function pointer. Solution: Check for NULL pointer. (closes https://github.com/vim/vim/issues/10319, closes https://github.com/vim/vim/issues/10319) diff --git a/src/eval.c b/src/eval.c --- a/src/eval.c +++ b/src/eval.c @@ -5314,7 +5314,8 @@ echo_string_core( if (echo_style) { - r = make_ufunc_name_readable(tv->vval.v_string, + r = tv->vval.v_string == NULL ? (char_u *)"function()" + : make_ufunc_name_readable(tv->vval.v_string, buf, MAX_FUNC_NAME_LEN); if (r == buf) { diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim --- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -4115,6 +4115,38 @@ def Run_Test_misplaced_type() delete('XTest_misplaced_type') enddef +" Ensure echo doesn't crash when stringifying empty variables. +def Test_echo_uninit_variables() + var res: string + + var var_bool: bool + var var_num: number + var var_float: float + var Var_func: func + var var_string: string + var var_blob: blob + var var_job: job + var var_channel: channel + var var_list: list + var var_dict: dict + + redir => res + echo var_bool + echo var_num + echo var_float + echo Var_func + echo var_string + echo var_blob + echo var_job + echo var_channel + echo var_list + echo var_dict + redir END + + assert_equal(['false', '0', '0.0', 'function()', '', '0z', 'no process', + 'channel fail', '[]', '{}'], res->split('\n')) +enddef + " Keep this last, it messes up highlighting. def Test_substitute_cmd() new diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -747,6 +747,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 4847, +/**/ 4846, /**/ 4845,