Mercurial > vim
comparison src/vim9execute.c @ 22808:96dbb61a54c2 v8.2.1952
patch 8.2.1952: Vim9: crash when using a NULL dict key
Commit: https://github.com/vim/vim/commit/c7f7f6db3e9d3b6b723ed17d5244c83859583832
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Nov 4 13:38:28 2020 +0100
patch 8.2.1952: Vim9: crash when using a NULL dict key
Problem: Vim9: crash when using a NULL dict key.
Solution: Use a NULL dict key like an empty string. (closes https://github.com/vim/vim/issues/7249)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 04 Nov 2020 13:45:05 +0100 |
parents | d235c5fa0bbe |
children | 2d05dd71aac3 |
comparison
equal
deleted
inserted
replaced
22807:606ff2127ead | 22808:96dbb61a54c2 |
---|---|
1736 case ISN_NEWDICT: | 1736 case ISN_NEWDICT: |
1737 { | 1737 { |
1738 int count = iptr->isn_arg.number; | 1738 int count = iptr->isn_arg.number; |
1739 dict_T *dict = dict_alloc(); | 1739 dict_T *dict = dict_alloc(); |
1740 dictitem_T *item; | 1740 dictitem_T *item; |
1741 char_u *key; | |
1741 | 1742 |
1742 if (dict == NULL) | 1743 if (dict == NULL) |
1743 goto failed; | 1744 goto failed; |
1744 for (idx = 0; idx < count; ++idx) | 1745 for (idx = 0; idx < count; ++idx) |
1745 { | 1746 { |
1746 // have already checked key type is VAR_STRING | 1747 // have already checked key type is VAR_STRING |
1747 tv = STACK_TV_BOT(2 * (idx - count)); | 1748 tv = STACK_TV_BOT(2 * (idx - count)); |
1748 // check key is unique | 1749 // check key is unique |
1749 item = dict_find(dict, tv->vval.v_string, -1); | 1750 key = tv->vval.v_string == NULL |
1751 ? (char_u *)"" : tv->vval.v_string; | |
1752 item = dict_find(dict, key, -1); | |
1750 if (item != NULL) | 1753 if (item != NULL) |
1751 { | 1754 { |
1752 SOURCING_LNUM = iptr->isn_lnum; | 1755 SOURCING_LNUM = iptr->isn_lnum; |
1753 semsg(_(e_duplicate_key), tv->vval.v_string); | 1756 semsg(_(e_duplicate_key), key); |
1754 dict_unref(dict); | 1757 dict_unref(dict); |
1755 goto on_error; | 1758 goto on_error; |
1756 } | 1759 } |
1757 item = dictitem_alloc(tv->vval.v_string); | 1760 item = dictitem_alloc(key); |
1758 clear_tv(tv); | 1761 clear_tv(tv); |
1759 if (item == NULL) | 1762 if (item == NULL) |
1760 { | 1763 { |
1761 dict_unref(dict); | 1764 dict_unref(dict); |
1762 goto failed; | 1765 goto failed; |