summaryrefslogtreecommitdiffstats
path: root/src/dict.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-08-07 21:42:24 +0200
committerBram Moolenaar <Bram@vim.org>2019-08-07 21:42:24 +0200
commitb59e7357722d977830948572a395f0a175c7ded8 (patch)
tree4b67980c7e04c9986a51368b51b554cc61b9d546 /src/dict.c
parent5bcc5a1ff94bbab1b175e35a72e3df974106b393 (diff)
patch 8.1.1825: allocating more memory than needed for extended structsv8.1.1825
Problem: Allocating more memory than needed for extended structs. Solution: Use offsetof() instead of sizeof(). (Dominique Pelle, closes #4785)
Diffstat (limited to 'src/dict.c')
-rw-r--r--src/dict.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/dict.c b/src/dict.c
index 45aa8246f1..1097e58cdc 100644
--- a/src/dict.c
+++ b/src/dict.c
@@ -210,7 +210,7 @@ dictitem_alloc(char_u *key)
{
dictitem_T *di;
- di = alloc(sizeof(dictitem_T) + STRLEN(key));
+ di = alloc(offsetof(dictitem_T, di_key) + STRLEN(key) + 1);
if (di != NULL)
{
STRCPY(di->di_key, key);
@@ -228,7 +228,7 @@ dictitem_copy(dictitem_T *org)
{
dictitem_T *di;
- di = alloc(sizeof(dictitem_T) + STRLEN(org->di_key));
+ di = alloc(offsetof(dictitem_T, di_key) + STRLEN(org->di_key) + 1);
if (di != NULL)
{
STRCPY(di->di_key, org->di_key);