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/syntax_defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/syntax_defs.h') diff --git a/src/nvim/syntax_defs.h b/src/nvim/syntax_defs.h index 3f3101f7e3..218cd3623d 100644 --- a/src/nvim/syntax_defs.h +++ b/src/nvim/syntax_defs.h @@ -30,7 +30,7 @@ struct keyentry { int16_t *next_list; // ID list for next match (if non-zero) int flags; int k_char; // conceal substitute character - char keyword[1]; // actually longer + char keyword[]; }; // Struct used to store one state of the state stack. -- cgit From 4f8941c1a5f1ef6caa410feeb52e343db22763ce Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 10 Nov 2023 12:23:42 +0100 Subject: refactor: replace manual header guards with #pragma once It is less error-prone than manually defining header guards. Pretty much all compilers support it even if it's not part of the C standard. --- src/nvim/syntax_defs.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/nvim/syntax_defs.h') diff --git a/src/nvim/syntax_defs.h b/src/nvim/syntax_defs.h index 218cd3623d..ae4997154e 100644 --- a/src/nvim/syntax_defs.h +++ b/src/nvim/syntax_defs.h @@ -1,5 +1,4 @@ -#ifndef NVIM_SYNTAX_DEFS_H -#define NVIM_SYNTAX_DEFS_H +#pragma once #include "nvim/highlight_defs.h" @@ -59,5 +58,3 @@ struct syn_state { linenr_T sst_change_lnum; // when non-zero, change in this line // may have made the state invalid }; - -#endif // NVIM_SYNTAX_DEFS_H -- cgit