neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit f9eb68f340f9c0dbf3b6b2da3ddbab2d5be21b61
parent 738320188ffc389f1dc04f67a06c280f2d4ae41d
Author: Justin M. Keyes <justinkz@gmail.com>
Date:   Wed, 18 Dec 2024 06:05:37 -0800

fix(coverity): error handling CHECKED_RETURN #31618

CID 516406:  Error handling issues  (CHECKED_RETURN)
    /src/nvim/api/vimscript.c: 284 in nvim_call_dict_function()
    278       Object rv = OBJECT_INIT;
    279
    280       typval_T rettv;
    281       bool mustfree = false;
    282       switch (dict.type) {
    283       case kObjectTypeString:
    >>>     CID 516406:  Error handling issues  (CHECKED_RETURN)
    >>>     Calling "eval0" without checking return value (as is done elsewhere 10 out of 12 times).
    284         TRY_WRAP(err, {
    285           eval0(dict.data.string.data, &rettv, NULL, &EVALARG_EVALUATE);
    286           clear_evalarg(&EVALARG_EVALUATE, NULL);
    287         });
    288         if (ERROR_SET(err)) {
    289           return rv;
Diffstat:
Msrc/nvim/api/vimscript.c | 20++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/nvim/api/vimscript.c b/src/nvim/api/vimscript.c @@ -229,10 +229,9 @@ static Object _call_function(String fn, Array args, dict_T *self, Arena *arena, funcexe.fe_selfdict = self; TRY_WRAP(err, { - // call_func() retval is deceptive, ignore it. Instead we set `msg_list` - // (see above) to capture abort-causing non-exception errors. - call_func(fn.data, (int)fn.size, &rettv, (int)args.size, - vim_args, &funcexe); + // call_func() retval is deceptive, ignore it. Instead TRY_WRAP sets `msg_list` to capture + // abort-causing non-exception errors. + (void)call_func(fn.data, (int)fn.size, &rettv, (int)args.size, vim_args, &funcexe); }); if (!ERROR_SET(err)) { @@ -280,18 +279,23 @@ Object nvim_call_dict_function(Object dict, String fn, Array args, Arena *arena, typval_T rettv; bool mustfree = false; switch (dict.type) { - case kObjectTypeString: + case kObjectTypeString: { + int eval_ret; TRY_WRAP(err, { - eval0(dict.data.string.data, &rettv, NULL, &EVALARG_EVALUATE); - clear_evalarg(&EVALARG_EVALUATE, NULL); - }); + eval_ret = eval0(dict.data.string.data, &rettv, NULL, &EVALARG_EVALUATE); + clear_evalarg(&EVALARG_EVALUATE, NULL); + }); if (ERROR_SET(err)) { return rv; } + if (eval_ret != OK) { + abort(); // Should not happen. + } // Evaluation of the string arg created a new dict or increased the // refcount of a dict. Not necessary for a RPC dict. mustfree = true; break; + } case kObjectTypeDict: object_to_vim(dict, &rettv, err); break;