Mercurial > vim
comparison src/dict.c @ 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 | ef23ec1eee54 |
children | 0f7ae8010787 |
comparison
equal
deleted
inserted
replaced
17654:8c3b0893d1fe | 17655:8f82b1ec99b7 |
---|---|
208 dictitem_T * | 208 dictitem_T * |
209 dictitem_alloc(char_u *key) | 209 dictitem_alloc(char_u *key) |
210 { | 210 { |
211 dictitem_T *di; | 211 dictitem_T *di; |
212 | 212 |
213 di = alloc(sizeof(dictitem_T) + STRLEN(key)); | 213 di = alloc(offsetof(dictitem_T, di_key) + STRLEN(key) + 1); |
214 if (di != NULL) | 214 if (di != NULL) |
215 { | 215 { |
216 STRCPY(di->di_key, key); | 216 STRCPY(di->di_key, key); |
217 di->di_flags = DI_FLAGS_ALLOC; | 217 di->di_flags = DI_FLAGS_ALLOC; |
218 di->di_tv.v_lock = 0; | 218 di->di_tv.v_lock = 0; |
226 static dictitem_T * | 226 static dictitem_T * |
227 dictitem_copy(dictitem_T *org) | 227 dictitem_copy(dictitem_T *org) |
228 { | 228 { |
229 dictitem_T *di; | 229 dictitem_T *di; |
230 | 230 |
231 di = alloc(sizeof(dictitem_T) + STRLEN(org->di_key)); | 231 di = alloc(offsetof(dictitem_T, di_key) + STRLEN(org->di_key) + 1); |
232 if (di != NULL) | 232 if (di != NULL) |
233 { | 233 { |
234 STRCPY(di->di_key, org->di_key); | 234 STRCPY(di->di_key, org->di_key); |
235 di->di_flags = DI_FLAGS_ALLOC; | 235 di->di_flags = DI_FLAGS_ALLOC; |
236 copy_tv(&org->di_tv, &di->di_tv); | 236 copy_tv(&org->di_tv, &di->di_tv); |