comparison src/vim9compile.c @ 21301:60011b87aae1 v8.2.1201

patch 8.2.1201: Vim9: crash when passing number as dict key Commit: https://github.com/vim/vim/commit/f1a2368d81fc3f70dfcf7d577957185da6ccf0b6 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jul 13 18:55:48 2020 +0200 patch 8.2.1201: Vim9: crash when passing number as dict key Problem: Vim9: crash when passing number as dict key. Solution: Check key type to be string. (closes https://github.com/vim/vim/issues/6449)
author Bram Moolenaar <Bram@vim.org>
date Mon, 13 Jul 2020 19:00:04 +0200
parents 13b1567ae0c6
children af3663df42bf
comparison
equal deleted inserted replaced
21300:59c9cfed9270 21301:60011b87aae1
3210 */ 3210 */
3211 static int 3211 static int
3212 compile_dict(char_u **arg, cctx_T *cctx, int literal) 3212 compile_dict(char_u **arg, cctx_T *cctx, int literal)
3213 { 3213 {
3214 garray_T *instr = &cctx->ctx_instr; 3214 garray_T *instr = &cctx->ctx_instr;
3215 garray_T *stack = &cctx->ctx_type_stack;
3215 int count = 0; 3216 int count = 0;
3216 dict_T *d = dict_alloc(); 3217 dict_T *d = dict_alloc();
3217 dictitem_T *item; 3218 dictitem_T *item;
3218 char_u *whitep = *arg; 3219 char_u *whitep = *arg;
3219 char_u *p; 3220 char_u *p;
3252 { 3253 {
3253 isn_T *isn; 3254 isn_T *isn;
3254 3255
3255 if (compile_expr0(arg, cctx) == FAIL) 3256 if (compile_expr0(arg, cctx) == FAIL)
3256 return FAIL; 3257 return FAIL;
3257 // TODO: check type is string
3258 isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1; 3258 isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1;
3259 if (isn->isn_type == ISN_PUSHS) 3259 if (isn->isn_type == ISN_PUSHS)
3260 key = isn->isn_arg.string; 3260 key = isn->isn_arg.string;
3261 else
3262 {
3263 type_T *keytype = ((type_T **)stack->ga_data)
3264 [stack->ga_len - 1];
3265 if (need_type(keytype, &t_string, -1, cctx, FALSE) == FAIL)
3266 return FAIL;
3267 }
3261 } 3268 }
3262 3269
3263 // Check for duplicate keys, if using string keys. 3270 // Check for duplicate keys, if using string keys.
3264 if (key != NULL) 3271 if (key != NULL)
3265 { 3272 {