Mercurial > vim
diff src/evalvars.c @ 31877:9f28cca2410a v9.0.1271
patch 9.0.1271: using sizeof() and subtract array size is tricky
Commit: https://github.com/vim/vim/commit/1b438a8228a415720efb5ca1c0503f5467292e8e
Author: zeertzjq <zeertzjq@outlook.com>
Date: Wed Feb 1 13:11:15 2023 +0000
patch 9.0.1271: using sizeof() and subtract array size is tricky
Problem: Using sizeof() and subtract array size is tricky.
Solution: Use offsetof() instead. (closes https://github.com/vim/vim/issues/11926)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 01 Feb 2023 14:15:04 +0100 |
parents | 7d505d77f6da |
children | 04d9dff67d99 |
line wrap: on
line diff
--- a/src/evalvars.c +++ b/src/evalvars.c @@ -3960,7 +3960,7 @@ set_var_const( || STRNCMP(name, "g:", 2) == 0 || var_in_autoload)) goto failed; - di = alloc(sizeof(dictitem_T) + STRLEN(varname)); + di = alloc(offsetof(dictitem_T, di_key) + STRLEN(varname) + 1); if (di == NULL) goto failed; STRCPY(di->di_key, varname);