Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
7964:78b678f510f4 | 7965:646d5148fee2 |
---|---|
851 } | 851 } |
852 else | 852 else |
853 { | 853 { |
854 typval_T *tv; | 854 typval_T *tv; |
855 typval_T err_tv; | 855 typval_T err_tv; |
856 char_u *json; | 856 char_u *json = NULL; |
857 | 857 |
858 /* Don't pollute the display with errors. */ | 858 /* Don't pollute the display with errors. */ |
859 ++emsg_skip; | 859 ++emsg_skip; |
860 tv = eval_expr(arg, NULL); | 860 tv = eval_expr(arg, NULL); |
861 --emsg_skip; | |
862 if (is_eval) | 861 if (is_eval) |
863 { | 862 { |
864 if (tv == NULL) | 863 if (tv != NULL) |
864 json = json_encode_nr_expr(arg3->vval.v_number, tv); | |
865 if (tv == NULL || (json != NULL && *json == NUL)) | |
865 { | 866 { |
867 /* If evaluation failed or the result can't be encoded | |
868 * then return the string "ERROR". */ | |
866 err_tv.v_type = VAR_STRING; | 869 err_tv.v_type = VAR_STRING; |
867 err_tv.vval.v_string = (char_u *)"ERROR"; | 870 err_tv.vval.v_string = (char_u *)"ERROR"; |
868 tv = &err_tv; | 871 tv = &err_tv; |
872 json = json_encode_nr_expr(arg3->vval.v_number, tv); | |
869 } | 873 } |
870 json = json_encode_nr_expr(arg3->vval.v_number, tv); | 874 if (json != NULL) |
871 channel_send(idx, json, "eval"); | 875 { |
872 vim_free(json); | 876 channel_send(idx, json, "eval"); |
877 vim_free(json); | |
878 } | |
873 } | 879 } |
880 --emsg_skip; | |
874 if (tv != &err_tv) | 881 if (tv != &err_tv) |
875 free_tv(tv); | 882 free_tv(tv); |
876 } | 883 } |
877 } | 884 } |
878 else if (p_verbose > 2) | 885 else if (p_verbose > 2) |