From a0961659770ca41edcb5a6dcf28e7c7492eb60f0 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 19 Oct 2023 18:34:48 +0800 Subject: vim-patch:9.0.2050: Vim9: crash with deferred function call and exception (#25715) Problem: Vim9: crash with deferred function call and exception Solution: Save and restore exception state Crash when a deferred function is called after an exception and another exception is thrown closes: vim/vim#13376 closes: vim/vim#13377 https://github.com/vim/vim/commit/c59c1e0d88651a71ece7366e418f1253abbe2a28 The change in check_due_timer() is N/A as Nvim calls timer callbacks on the main loop. Co-authored-by: Yegappan Lakshmanan --- src/nvim/eval/userfunc.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index f789c53870..ff86f74338 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -3297,21 +3297,16 @@ static void handle_defer_one(funccall_T *funccal) dr->dr_name = NULL; // If the deferred function is called after an exception, then only the - // first statement in the function will be executed. Save and restore - // the try/catch/throw exception state. - const int save_trylevel = trylevel; - const bool save_did_throw = did_throw; - const bool save_need_rethrow = need_rethrow; - - trylevel = 0; - did_throw = false; - need_rethrow = false; + // first statement in the function will be executed (because of the + // exception). So save and restore the try/catch/throw exception + // state. + exception_state_T estate; + exception_state_save(&estate); + exception_state_clear(); call_func(name, -1, &rettv, dr->dr_argcount, dr->dr_argvars, &funcexe); - trylevel = save_trylevel; - did_throw = save_did_throw; - need_rethrow = save_need_rethrow; + exception_state_restore(&estate); tv_clear(&rettv); xfree(name); -- cgit