]> granicus.if.org Git - vim/commitdiff
patch 8.1.1825: allocating more memory than needed for extended structs v8.1.1825
authorBram Moolenaar <Bram@vim.org>
Wed, 7 Aug 2019 19:42:24 +0000 (21:42 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 7 Aug 2019 19:42:24 +0000 (21:42 +0200)
Problem:    Allocating more memory than needed for extended structs.
Solution:   Use offsetof() instead of sizeof(). (Dominique Pelle,
            closes #4785)

src/dict.c
src/version.c

index 45aa8246f11877282862c8d849643cb45aa9371b..1097e58cdc32eff67d87cdc715d2785886106958 100644 (file)
@@ -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);
index 53c7a9d1ba00b452358e33d1810eda3f9e711458..3bb1cfd54bd92eff0916afc8c0577a3038c1ce14 100644 (file)
@@ -769,6 +769,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1825,
 /**/
     1824,
 /**/