mirror of
https://github.com/neovim/neovim.git
synced 2025-10-03 00:18:33 +00:00
vim-patch:9.0.1271: using sizeof() and subtract array size is tricky (#22087)
Problem: Using sizeof() and subtract array size is tricky.
Solution: Use offsetof() instead. (closes vim/vim#11926)
1b438a8228
This commit is contained in:
@@ -1347,7 +1347,7 @@ void set_var_const(const char *name, const size_t name_len, typval_T *const tv,
|
||||
// Make sure dict is valid
|
||||
assert(dict != NULL);
|
||||
|
||||
v = xmalloc(sizeof(dictitem_T) + strlen(varname));
|
||||
v = xmalloc(offsetof(dictitem_T, di_key) + strlen(varname) + 1);
|
||||
STRCPY(v->di_key, varname);
|
||||
if (hash_add(ht, (char *)v->di_key) == FAIL) {
|
||||
xfree(v);
|
||||
|
Reference in New Issue
Block a user