comparison src/strings.c @ 25252:acda780ffc3e v8.2.3162

patch 8.2.3162: Vim9: argument types are not checked at compile time Commit: https://github.com/vim/vim/commit/1a71d31bf34b0b2b08517903826004ec6fd440e5 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Thu Jul 15 12:49:58 2021 +0200 patch 8.2.3162: Vim9: argument types are not checked at compile time Problem: Vim9: argument types are not checked at compile time. Solution: Add more type checks. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/8560)
author Bram Moolenaar <Bram@vim.org>
date Thu, 15 Jul 2021 13:00:06 +0200
parents dc66d0284518
children 712e867f9721
comparison
equal deleted inserted replaced
25251:6024f64e0d2b 25252:acda780ffc3e
793 { 793 {
794 char_u *t; 794 char_u *t;
795 char_u *str; 795 char_u *str;
796 varnumber_T idx; 796 varnumber_T idx;
797 797
798 rettv->vval.v_number = -1;
799
800 if (in_vim9script()
801 && (check_for_string_arg(argvars, 0) == FAIL
802 || check_for_number_arg(argvars, 1) == FAIL))
803 return;
804
798 str = tv_get_string_chk(&argvars[0]); 805 str = tv_get_string_chk(&argvars[0]);
799 idx = tv_get_number_chk(&argvars[1], NULL); 806 idx = tv_get_number_chk(&argvars[1], NULL);
800 rettv->vval.v_number = -1;
801 if (str == NULL || idx < 0) 807 if (str == NULL || idx < 0)
802 return; 808 return;
803 809
804 t = str; 810 t = str;
805 for ( ; idx > 0; idx--) 811 for ( ; idx > 0; idx--)
979 int error = FALSE; 985 int error = FALSE;
980 int charidx; 986 int charidx;
981 int byteidx = 0; 987 int byteidx = 0;
982 988
983 rettv->vval.v_number = -1; 989 rettv->vval.v_number = -1;
990
991 if (in_vim9script()
992 && (check_for_string_arg(argvars, 0) == FAIL
993 || check_for_number_arg(argvars, 1) == FAIL))
994 return;
995
984 str = tv_get_string_chk(&argvars[0]); 996 str = tv_get_string_chk(&argvars[0]);
985 if (str == NULL) 997 if (str == NULL)
986 return; 998 return;
987 len = (int)STRLEN(str); 999 len = (int)STRLEN(str);
988 charidx = (int)tv_get_number_chk(&argvars[1], &error); 1000 charidx = (int)tv_get_number_chk(&argvars[1], &error);
1108 * "strdisplaywidth()" function 1120 * "strdisplaywidth()" function
1109 */ 1121 */
1110 void 1122 void
1111 f_strdisplaywidth(typval_T *argvars, typval_T *rettv) 1123 f_strdisplaywidth(typval_T *argvars, typval_T *rettv)
1112 { 1124 {
1113 char_u *s = tv_get_string(&argvars[0]); 1125 char_u *s;
1114 int col = 0; 1126 int col = 0;
1115 1127
1128 rettv->vval.v_number = -1;
1129
1130 if (in_vim9script()
1131 && (check_for_string_arg(argvars, 0) == FAIL
1132 || (argvars[1].v_type != VAR_UNKNOWN
1133 && check_for_number_arg(argvars, 1) == FAIL)))
1134 return;
1135
1136 s = tv_get_string(&argvars[0]);
1116 if (argvars[1].v_type != VAR_UNKNOWN) 1137 if (argvars[1].v_type != VAR_UNKNOWN)
1117 col = (int)tv_get_number(&argvars[1]); 1138 col = (int)tv_get_number(&argvars[1]);
1118 1139
1119 rettv->vval.v_number = (varnumber_T)(linetabsize_col(col, s) - col); 1140 rettv->vval.v_number = (varnumber_T)(linetabsize_col(col, s) - col);
1120 } 1141 }