changeset 17655:8f82b1ec99b7 v8.1.1825

patch 8.1.1825: allocating more memory than needed for extended structs commit https://github.com/vim/vim/commit/b59e7357722d977830948572a395f0a175c7ded8 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Aug 7 21:42:24 2019 +0200 patch 8.1.1825: allocating more memory than needed for extended structs Problem: Allocating more memory than needed for extended structs. Solution: Use offsetof() instead of sizeof(). (Dominique Pelle, closes #4785)
author Bram Moolenaar <Bram@vim.org>
date Wed, 07 Aug 2019 21:45:06 +0200
parents 8c3b0893d1fe
children 2adce9da20d8
files src/dict.c src/version.c
diffstat 2 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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);
--- a/src/version.c
+++ b/src/version.c
@@ -770,6 +770,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1825,
+/**/
     1824,
 /**/
     1823,