diff options
author | dundargoc <33953936+dundargoc@users.noreply.github.com> | 2023-02-02 23:56:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-02 23:56:25 +0100 |
commit | ebd2372f928c6f1cfe823d36aabf479f6930232f (patch) | |
tree | 277d19740498c2be4486df9bd8dd411b5b4547d1 /src/nvim/regexp_defs.h | |
parent | 0ea4156464c982f0451cd486e2152934c3dd2204 (diff) | |
download | rneovim-ebd2372f928c6f1cfe823d36aabf479f6930232f.tar.gz rneovim-ebd2372f928c6f1cfe823d36aabf479f6930232f.tar.bz2 rneovim-ebd2372f928c6f1cfe823d36aabf479f6930232f.zip |
refactor: use flexible arrays instead of the length-of-one trick (#22072)
The "length-of-one" trick, where the last element of a struct is an
array of size 1, but extra size is allocated when calling malloc where
it uses more than 1 element in the array, cause problems with some
compilers. Some compilers set _FORTIFY_SOURCE=2 by default which
incorrectly considers it as an overflow. More information:
https://github.com/neovim/neovim/issues/223#issuecomment-1413828554
Using flexible array members allows us to to properly convey to the
compiler that its size may be larger than 1. This also enables us to
remove lengthy workarounds that are unreliable, as they depend on
CMAKE_BUILD_TYPE which isn't defined for multi-config generators.
Closes: https://github.com/neovim/neovim/issues/223
Diffstat (limited to 'src/nvim/regexp_defs.h')
-rw-r--r-- | src/nvim/regexp_defs.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/nvim/regexp_defs.h b/src/nvim/regexp_defs.h index 16bb2db464..b27a5b5942 100644 --- a/src/nvim/regexp_defs.h +++ b/src/nvim/regexp_defs.h @@ -102,7 +102,7 @@ typedef struct { char_u *regmust; int regmlen; char_u reghasz; - char_u program[1]; // actually longer.. + char_u program[]; } bt_regprog_T; // Structure representing a NFA state. @@ -138,7 +138,7 @@ typedef struct { char *pattern; int nsubexp; // number of () int nstate; - nfa_state_T state[1]; // actually longer.. + nfa_state_T state[]; } nfa_regprog_T; // Structure to be used for single-line matching. |