Mercurial > vim
comparison src/evalfunc.c @ 29175:755ab148288b v8.2.5107
patch 8.2.5107: some callers of rettv_list_alloc() check for not OK
Commit: https://github.com/vim/vim/commit/93a1096fe48e12095544924adb267e3b8a16b221
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Jun 16 11:42:09 2022 +0100
patch 8.2.5107: some callers of rettv_list_alloc() check for not OK
Problem: Some callers of rettv_list_alloc() check for not OK. (Christ van
Willegen)
Solution: Use "==" instead of "!=" when checking the return value.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 16 Jun 2022 12:45:03 +0200 |
parents | 175eacde28b8 |
children | d1e263ecf634 |
comparison
equal
deleted
inserted
replaced
29174:a13f0046b5ef | 29175:755ab148288b |
---|---|
3730 # endif | 3730 # endif |
3731 # else | 3731 # else |
3732 extern char **environ; | 3732 extern char **environ; |
3733 # endif | 3733 # endif |
3734 | 3734 |
3735 if (rettv_dict_alloc(rettv) != OK) | 3735 if (rettv_dict_alloc(rettv) == FAIL) |
3736 return; | 3736 return; |
3737 | 3737 |
3738 # ifdef MSWIN | 3738 # ifdef MSWIN |
3739 if (*_wenviron == NULL) | 3739 if (*_wenviron == NULL) |
3740 return; | 3740 return; |
4157 --emsg_off; | 4157 --emsg_off; |
4158 else if (errormsg != NULL) | 4158 else if (errormsg != NULL) |
4159 emsg(errormsg); | 4159 emsg(errormsg); |
4160 if (rettv->v_type == VAR_LIST) | 4160 if (rettv->v_type == VAR_LIST) |
4161 { | 4161 { |
4162 if (rettv_list_alloc(rettv) != FAIL && result != NULL) | 4162 if (rettv_list_alloc(rettv) == OK && result != NULL) |
4163 list_append_string(rettv->vval.v_list, result, -1); | 4163 list_append_string(rettv->vval.v_list, result, -1); |
4164 vim_free(result); | 4164 vim_free(result); |
4165 } | 4165 } |
4166 else | 4166 else |
4167 rettv->vval.v_string = result; | 4167 rettv->vval.v_string = result; |
4180 if (p_wic) | 4180 if (p_wic) |
4181 options += WILD_ICASE; | 4181 options += WILD_ICASE; |
4182 if (rettv->v_type == VAR_STRING) | 4182 if (rettv->v_type == VAR_STRING) |
4183 rettv->vval.v_string = ExpandOne(&xpc, s, NULL, | 4183 rettv->vval.v_string = ExpandOne(&xpc, s, NULL, |
4184 options, WILD_ALL); | 4184 options, WILD_ALL); |
4185 else if (rettv_list_alloc(rettv) != FAIL) | 4185 else if (rettv_list_alloc(rettv) == OK) |
4186 { | 4186 { |
4187 int i; | 4187 int i; |
4188 | 4188 |
4189 ExpandOne(&xpc, s, NULL, options, WILD_ALL_KEEP); | 4189 ExpandOne(&xpc, s, NULL, options, WILD_ALL_KEEP); |
4190 for (i = 0; i < xpc.xp_numfiles; i++) | 4190 for (i = 0; i < xpc.xp_numfiles; i++) |
4782 int i; | 4782 int i; |
4783 list_T *l; | 4783 list_T *l; |
4784 dict_T *d; | 4784 dict_T *d; |
4785 int changelistindex; | 4785 int changelistindex; |
4786 | 4786 |
4787 if (rettv_list_alloc(rettv) != OK) | 4787 if (rettv_list_alloc(rettv) == FAIL) |
4788 return; | 4788 return; |
4789 | 4789 |
4790 if (in_vim9script() && check_for_opt_buffer_arg(argvars, 0) == FAIL) | 4790 if (in_vim9script() && check_for_opt_buffer_arg(argvars, 0) == FAIL) |
4791 return; | 4791 return; |
4792 | 4792 |
4927 * "getcharsearch()" function | 4927 * "getcharsearch()" function |
4928 */ | 4928 */ |
4929 static void | 4929 static void |
4930 f_getcharsearch(typval_T *argvars UNUSED, typval_T *rettv) | 4930 f_getcharsearch(typval_T *argvars UNUSED, typval_T *rettv) |
4931 { | 4931 { |
4932 if (rettv_dict_alloc(rettv) != FAIL) | 4932 if (rettv_dict_alloc(rettv) == OK) |
4933 { | 4933 { |
4934 dict_T *dict = rettv->vval.v_dict; | 4934 dict_T *dict = rettv->vval.v_dict; |
4935 | 4935 |
4936 dict_add_string(dict, "char", last_csearch()); | 4936 dict_add_string(dict, "char", last_csearch()); |
4937 dict_add_number(dict, "forward", last_csearch_forward()); | 4937 dict_add_number(dict, "forward", last_csearch_forward()); |
5014 win_T *wp; | 5014 win_T *wp; |
5015 int i; | 5015 int i; |
5016 list_T *l; | 5016 list_T *l; |
5017 dict_T *d; | 5017 dict_T *d; |
5018 | 5018 |
5019 if (rettv_list_alloc(rettv) != OK) | 5019 if (rettv_list_alloc(rettv) == FAIL) |
5020 return; | 5020 return; |
5021 | 5021 |
5022 if (in_vim9script() | 5022 if (in_vim9script() |
5023 && (check_for_opt_number_arg(argvars, 0) == FAIL | 5023 && (check_for_opt_number_arg(argvars, 0) == FAIL |
5024 || (argvars[0].v_type != VAR_UNKNOWN | 5024 || (argvars[0].v_type != VAR_UNKNOWN |
5219 static void | 5219 static void |
5220 f_gettagstack(typval_T *argvars, typval_T *rettv) | 5220 f_gettagstack(typval_T *argvars, typval_T *rettv) |
5221 { | 5221 { |
5222 win_T *wp = curwin; // default is current window | 5222 win_T *wp = curwin; // default is current window |
5223 | 5223 |
5224 if (rettv_dict_alloc(rettv) != OK) | 5224 if (rettv_dict_alloc(rettv) == FAIL) |
5225 return; | 5225 return; |
5226 | 5226 |
5227 if (in_vim9script() && check_for_opt_number_arg(argvars, 0) == FAIL) | 5227 if (in_vim9script() && check_for_opt_number_arg(argvars, 0) == FAIL) |
5228 return; | 5228 return; |
5229 | 5229 |
7842 * "pum_getpos()" function | 7842 * "pum_getpos()" function |
7843 */ | 7843 */ |
7844 static void | 7844 static void |
7845 f_pum_getpos(typval_T *argvars UNUSED, typval_T *rettv UNUSED) | 7845 f_pum_getpos(typval_T *argvars UNUSED, typval_T *rettv UNUSED) |
7846 { | 7846 { |
7847 if (rettv_dict_alloc(rettv) != OK) | 7847 if (rettv_dict_alloc(rettv) == FAIL) |
7848 return; | 7848 return; |
7849 pum_set_event_info(rettv->vval.v_dict); | 7849 pum_set_event_info(rettv->vval.v_dict); |
7850 } | 7850 } |
7851 | 7851 |
7852 /* | 7852 /* |
8131 varnumber_T start; | 8131 varnumber_T start; |
8132 varnumber_T end; | 8132 varnumber_T end; |
8133 varnumber_T stride = 1; | 8133 varnumber_T stride = 1; |
8134 int error = FALSE; | 8134 int error = FALSE; |
8135 | 8135 |
8136 if (rettv_list_alloc(rettv) != OK) | 8136 if (rettv_list_alloc(rettv) == FAIL) |
8137 return; | 8137 return; |
8138 | 8138 |
8139 if (in_vim9script() | 8139 if (in_vim9script() |
8140 && (check_for_number_arg(argvars, 0) == FAIL | 8140 && (check_for_number_arg(argvars, 0) == FAIL |
8141 || check_for_opt_number_arg(argvars, 1) == FAIL | 8141 || check_for_opt_number_arg(argvars, 1) == FAIL |
10195 lnum = tv_get_lnum(argvars); // -1 on type error | 10195 lnum = tv_get_lnum(argvars); // -1 on type error |
10196 col = (colnr_T)tv_get_number(&argvars[1]) - 1; // -1 on type error | 10196 col = (colnr_T)tv_get_number(&argvars[1]) - 1; // -1 on type error |
10197 | 10197 |
10198 CLEAR_FIELD(str); | 10198 CLEAR_FIELD(str); |
10199 | 10199 |
10200 if (rettv_list_alloc(rettv) != FAIL) | 10200 if (rettv_list_alloc(rettv) == OK) |
10201 { | 10201 { |
10202 if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count | 10202 if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count |
10203 && col >= 0 && col <= (long)STRLEN(ml_get(lnum)) | 10203 && col >= 0 && col <= (long)STRLEN(ml_get(lnum)) |
10204 && curwin->w_p_cole > 0) | 10204 && curwin->w_p_cole > 0) |
10205 { | 10205 { |
10256 lnum = tv_get_lnum(argvars); // -1 on type error | 10256 lnum = tv_get_lnum(argvars); // -1 on type error |
10257 col = (colnr_T)tv_get_number(&argvars[1]) - 1; // -1 on type error | 10257 col = (colnr_T)tv_get_number(&argvars[1]) - 1; // -1 on type error |
10258 | 10258 |
10259 if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count | 10259 if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count |
10260 && col >= 0 && col <= (long)STRLEN(ml_get(lnum)) | 10260 && col >= 0 && col <= (long)STRLEN(ml_get(lnum)) |
10261 && rettv_list_alloc(rettv) != FAIL) | 10261 && rettv_list_alloc(rettv) == OK) |
10262 { | 10262 { |
10263 (void)syn_get_id(curwin, lnum, col, FALSE, NULL, TRUE); | 10263 (void)syn_get_id(curwin, lnum, col, FALSE, NULL, TRUE); |
10264 for (i = 0; ; ++i) | 10264 for (i = 0; ; ++i) |
10265 { | 10265 { |
10266 id = syn_get_stack_item(i); | 10266 id = syn_get_stack_item(i); |
10291 { | 10291 { |
10292 tp = find_tabpage((int)tv_get_number(&argvars[0])); | 10292 tp = find_tabpage((int)tv_get_number(&argvars[0])); |
10293 if (tp != NULL) | 10293 if (tp != NULL) |
10294 wp = (tp == curtab) ? firstwin : tp->tp_firstwin; | 10294 wp = (tp == curtab) ? firstwin : tp->tp_firstwin; |
10295 } | 10295 } |
10296 if (wp != NULL && rettv_list_alloc(rettv) != FAIL) | 10296 if (wp != NULL && rettv_list_alloc(rettv) == OK) |
10297 { | 10297 { |
10298 for (; wp != NULL; wp = wp->w_next) | 10298 for (; wp != NULL; wp = wp->w_next) |
10299 if (list_append_number(rettv->vval.v_list, | 10299 if (list_append_number(rettv->vval.v_list, |
10300 wp->w_buffer->b_fnum) == FAIL) | 10300 wp->w_buffer->b_fnum) == FAIL) |
10301 break; | 10301 break; |