From ebd2372f928c6f1cfe823d36aabf479f6930232f Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Thu, 2 Feb 2023 23:56:25 +0100 Subject: 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 --- src/nvim/file_search.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/file_search.c') diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index a0435afd65..42ba0bee97 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -117,7 +117,7 @@ typedef struct ff_visited { FileID file_id; // The memory for this struct is allocated according to the length of // ffv_fname. - char ffv_fname[1]; // actually longer + char ffv_fname[]; } ff_visited_T; // We might have to manage several visited lists during a search. -- cgit