Skip to content

Commit c5654b8

Browse files
h-eastchrisbra
authored andcommitted
patch 9.1.1097: --log with non-existent path causes a crash
Problem: --log with non-existent path causes a crash (Ekkosun) Solution: split initialization phase and init the execution stack earlier (Hirohito Higashi) fixes: #16606 closes: #16610 Signed-off-by: Hirohito Higashi <h.east.727@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 97baa1c commit c5654b8

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

Diff for: src/main.c

+17-4
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ main
144144
atexit(vim_mem_profile_dump);
145145
#endif
146146

147+
/*
148+
* Various initialisations #1 shared with tests.
149+
*/
150+
common_init_1();
151+
147152
#if defined(STARTUPTIME) || defined(FEAT_JOB_CHANNEL)
148153
// Need to find "--startuptime" and "--log" before actually parsing
149154
// arguments.
@@ -185,9 +190,9 @@ main
185190
#endif
186191

187192
/*
188-
* Various initialisations shared with tests.
193+
* Various initialisations #2 shared with tests.
189194
*/
190-
common_init(&params);
195+
common_init_2(&params);
191196

192197
#ifdef VIMDLL
193198
// Check if the current executable file is for the GUI subsystem.
@@ -900,10 +905,10 @@ vim_main2(void)
900905
}
901906

902907
/*
903-
* Initialisation shared by main() and some tests.
908+
* Initialisation #1 shared by main() and some tests.
904909
*/
905910
void
906-
common_init(mparm_T *paramp)
911+
common_init_1(void)
907912
{
908913
estack_init();
909914
cmdline_init();
@@ -925,7 +930,15 @@ common_init(mparm_T *paramp)
925930
|| (NameBuff = alloc(MAXPATHL)) == NULL)
926931
mch_exit(0);
927932
TIME_MSG("Allocated generic buffers");
933+
}
934+
928935

936+
/*
937+
* Initialisation #2 shared by main() and some tests.
938+
*/
939+
void
940+
common_init_2(mparm_T *paramp)
941+
{
929942
#ifdef NBDEBUG
930943
// Wait a moment for debugging NetBeans. Must be after allocating
931944
// NameBuff.

Diff for: src/message_test.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,8 @@ main(int argc, char **argv)
508508
CLEAR_FIELD(params);
509509
params.argc = argc;
510510
params.argv = argv;
511-
common_init(&params);
511+
common_init_1();
512+
common_init_2(&params);
512513

513514
set_option_value_give_err((char_u *)"encoding", 0, (char_u *)"utf-8", 0);
514515
init_chartab();

Diff for: src/proto/main.pro

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* main.c */
22
int vim_main2(void);
3-
void common_init(mparm_T *paramp);
3+
void common_init_1(void);
4+
void common_init_2(mparm_T *paramp);
45
int is_not_a_term(void);
56
int is_not_a_term_or_gui(void);
67
void free_vbuf(void);

Diff for: src/testdir/test_startup.vim

+7
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,13 @@ func Test_log()
740740
call delete('Xlogfile')
741741
endfunc
742742

743+
func Test_log_nonexistent()
744+
" this used to crash Vim
745+
CheckFeature channel
746+
let result = join(systemlist(GetVimCommand() .. ' --log /X/Xlogfile -c qa!'))
747+
call assert_match("E484: Can't open file", result)
748+
endfunc
749+
743750
func Test_read_stdin()
744751
let after =<< trim [CODE]
745752
write Xtestout

Diff for: src/version.c

+2
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
1097,
707709
/**/
708710
1096,
709711
/**/

0 commit comments

Comments
 (0)