Mercurial > vim
diff src/channel.c @ 7965:646d5148fee2 v7.4.1278
commit https://github.com/vim/vim/commit/55fab439a6f3bba6dbe780ac034b84d5822a1a96
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Feb 7 16:53:13 2016 +0100
patch 7.4.1278
Problem: When jsonencode() fails it still returns something.
Solution: Return an empty string on failure.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 07 Feb 2016 17:00:05 +0100 |
parents | a7e58c6e4e9a |
children | 45ea5ebf3a98 |
line wrap: on
line diff
--- a/src/channel.c +++ b/src/channel.c @@ -853,24 +853,31 @@ channel_exe_cmd(int idx, char_u *cmd, ty { typval_T *tv; typval_T err_tv; - char_u *json; + char_u *json = NULL; /* Don't pollute the display with errors. */ ++emsg_skip; tv = eval_expr(arg, NULL); - --emsg_skip; if (is_eval) { - if (tv == NULL) + if (tv != NULL) + json = json_encode_nr_expr(arg3->vval.v_number, tv); + if (tv == NULL || (json != NULL && *json == NUL)) { + /* If evaluation failed or the result can't be encoded + * then return the string "ERROR". */ err_tv.v_type = VAR_STRING; err_tv.vval.v_string = (char_u *)"ERROR"; tv = &err_tv; + json = json_encode_nr_expr(arg3->vval.v_number, tv); } - json = json_encode_nr_expr(arg3->vval.v_number, tv); - channel_send(idx, json, "eval"); - vim_free(json); + if (json != NULL) + { + channel_send(idx, json, "eval"); + vim_free(json); + } } + --emsg_skip; if (tv != &err_tv) free_tv(tv); }