From b8df2c6ebd96f2cb06e19da909623085d7b23932 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sun, 7 Apr 2019 19:50:54 -0400 Subject: [PATCH 1/3] Make SHM_ALL to a variable instead of a compound literal #define gcc-9 has [improved compliance] with the C spec for lifetime of compound literals, tying their lifetime to block scope instead of function scope. This makes the behavior comparable to all other automatic variables. Using the SHM_ALL #define instantiated a compound literal local to an if clause and assigned the address to a "char_u *". Since the pointer was then being used outside of the if clause, it was using an invalid address. [improved compliance]: https://gcc.gnu.org/gcc-9/porting_to.html#complit Closes #9855 --- src/nvim/option.c | 9 +++++++++ src/nvim/option_defs.h | 8 -------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/nvim/option.c b/src/nvim/option.c index 348649036669c8..30dabcdd7df86c 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -310,6 +310,15 @@ static char *(p_scl_values[]) = { "yes", "no", "auto", "auto:1", "auto:2", "yes:1", "yes:2", "yes:3", "yes:4", "yes:5", "yes:6", "yes:7", "yes:8", "yes:9", NULL }; +/// All possible flags for 'shm'. +static char_u SHM_ALL[] = { + SHM_RO, SHM_MOD, SHM_FILE, SHM_LAST, SHM_TEXT, SHM_LINES, SHM_NEW, SHM_WRI, + SHM_ABBREVIATIONS, SHM_WRITE, SHM_TRUNC, SHM_TRUNCALL, SHM_OVER, + SHM_OVERALL, SHM_SEARCH, SHM_ATTENTION, SHM_INTRO, SHM_COMPLETIONMENU, + SHM_RECORDING, SHM_FILEINFO, + 0, +}; + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "option.c.generated.h" #endif diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index c71ce9175b5f69..2075d2819cacc0 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -179,14 +179,6 @@ enum { SHM_RO, SHM_MOD, SHM_FILE, SHM_LAST, SHM_TEXT, SHM_LINES, SHM_NEW, SHM_WRI, \ 0, \ }) -/// All possible flags for 'shm'. -#define SHM_ALL ((char_u[]) { \ - SHM_RO, SHM_MOD, SHM_FILE, SHM_LAST, SHM_TEXT, SHM_LINES, SHM_NEW, SHM_WRI, \ - SHM_ABBREVIATIONS, SHM_WRITE, SHM_TRUNC, SHM_TRUNCALL, SHM_OVER, \ - SHM_OVERALL, SHM_SEARCH, SHM_ATTENTION, SHM_INTRO, SHM_COMPLETIONMENU, \ - SHM_RECORDING, SHM_FILEINFO, \ - 0, \ -}) /* characters for p_go: */ #define GO_ASEL 'a' /* autoselect */ From 6572c995fb5a3b7dc41f077e0434810e6679f96d Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sun, 7 Apr 2019 20:01:05 -0400 Subject: [PATCH 2/3] Remove MSVC optimization workaround for SHM_ALL --- src/nvim/option.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/nvim/option.c b/src/nvim/option.c index 30dabcdd7df86c..026d8e21214b43 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2495,11 +2495,6 @@ static bool valid_filetype(char_u *val) return true; } -#ifdef _MSC_VER -// MSVC optimizations are disabled for this function because it -// incorrectly generates an empty string for SHM_ALL. -#pragma optimize("", off) -#endif /* * Handle string options that need some action to perform when changed. * Returns NULL for success, or an error message for an error. @@ -3391,9 +3386,6 @@ did_set_string_option( return errmsg; } -#ifdef _MSC_VER -#pragma optimize("", on) -#endif /* * Simple int comparison function for use with qsort() From 61eff5d23826e423e29bc21de09e181921028c7c Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 8 Apr 2019 08:02:44 -0400 Subject: [PATCH 3/3] lint --- src/nvim/option.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/nvim/option.c b/src/nvim/option.c index 026d8e21214b43..bfb1de096da953 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2495,10 +2495,8 @@ static bool valid_filetype(char_u *val) return true; } -/* - * Handle string options that need some action to perform when changed. - * Returns NULL for success, or an error message for an error. - */ +/// Handle string options that need some action to perform when changed. +/// Returns NULL for success, or an error message for an error. static char_u * did_set_string_option( int opt_idx, // index in options[] table @@ -3387,18 +3385,15 @@ did_set_string_option( return errmsg; } -/* - * Simple int comparison function for use with qsort() - */ +/// Simple int comparison function for use with qsort() static int int_cmp(const void *a, const void *b) { return *(const int *)a - *(const int *)b; } -/* - * Handle setting 'colorcolumn' or 'textwidth' in window "wp". - * Returns error message, NULL if it's OK. - */ +/// Handle setting 'colorcolumn' or 'textwidth' in window "wp". +/// +/// @return error message, NULL if it's OK. char_u *check_colorcolumn(win_T *wp) { char_u *s;