To: vim_dev@googlegroups.com Subject: Patch 8.1.1825 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.1825 Problem: Allocating more memory than needed for extended structs. Solution: Use offsetof() instead of sizeof(). (Dominique Pelle, closes #4785) Files: src/dict.c *** ../vim-8.1.1824/src/dict.c 2019-07-27 23:12:08.667924110 +0200 --- src/dict.c 2019-08-07 21:34:26.138992400 +0200 *************** *** 210,216 **** { dictitem_T *di; ! di = alloc(sizeof(dictitem_T) + STRLEN(key)); if (di != NULL) { STRCPY(di->di_key, key); --- 210,216 ---- { dictitem_T *di; ! di = alloc(offsetof(dictitem_T, di_key) + STRLEN(key) + 1); if (di != NULL) { STRCPY(di->di_key, key); *************** *** 228,234 **** { dictitem_T *di; ! di = alloc(sizeof(dictitem_T) + STRLEN(org->di_key)); if (di != NULL) { STRCPY(di->di_key, org->di_key); --- 228,234 ---- { dictitem_T *di; ! di = alloc(offsetof(dictitem_T, di_key) + STRLEN(org->di_key) + 1); if (di != NULL) { STRCPY(di->di_key, org->di_key); *** ../vim-8.1.1824/src/version.c 2019-08-06 22:47:57.112635782 +0200 --- src/version.c 2019-08-07 21:36:19.770401825 +0200 *************** *** 771,772 **** --- 771,774 ---- { /* Add new patch number below this line */ + /**/ + 1825, /**/ -- The technology involved in making anything invisible is so infinitely complex that nine hundred and ninety-nine billion, nine hundred and ninety-nine million, nine hundred and ninety-nine thousand, nine hundred and ninety-nine times out of a trillion it is much simpler and more effective just to take the thing away and do without it. -- Douglas Adams, "The Hitchhiker's Guide to the Galaxy" /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///