Mercurial > vim
comparison src/sign.c @ 17659:121bdff812b4 v8.1.1827
patch 8.1.1827: allocating more memory than needed for extended structs
commit https://github.com/vim/vim/commit/47ed553fd5bebfc36eb8aa81686eeaa5a84eccac
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Aug 8 20:49:14 2019 +0200
patch 8.1.1827: 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 #4786)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 08 Aug 2019 21:00:07 +0200 |
parents | a5874fdc8f3a |
children | 04245f071792 |
comparison
equal
deleted
inserted
replaced
17658:0d763089ba7f | 17659:121bdff812b4 |
---|---|
83 hash = hash_hash(groupname); | 83 hash = hash_hash(groupname); |
84 hi = hash_lookup(&sg_table, groupname, hash); | 84 hi = hash_lookup(&sg_table, groupname, hash); |
85 if (HASHITEM_EMPTY(hi)) | 85 if (HASHITEM_EMPTY(hi)) |
86 { | 86 { |
87 // new group | 87 // new group |
88 group = alloc(sizeof(signgroup_T) + STRLEN(groupname)); | 88 group = alloc(offsetof(signgroup_T, sg_name) + STRLEN(groupname) + 1); |
89 if (group == NULL) | 89 if (group == NULL) |
90 return NULL; | 90 return NULL; |
91 STRCPY(group->sg_name, groupname); | 91 STRCPY(group->sg_name, groupname); |
92 group->refcount = 1; | 92 group->refcount = 1; |
93 group->next_sign_id = 1; | 93 group->next_sign_id = 1; |