aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhlosioneer <mattmdrr2@gmail.com>2017-11-20 18:04:49 -0500
committerJustin M. Keyes <justinkz@gmail.com>2017-11-21 00:04:49 +0100
commit8674b0c3d161bd367ff63c6a8fb290fec0122d05 (patch)
tree18e4224a4c9f19c1dd5b3fd303bd247967667e51
parentc39140164877ce51d5785405205a570b45cc5f82 (diff)
downloadrneovim-8674b0c3d161bd367ff63c6a8fb290fec0122d05.tar.gz
rneovim-8674b0c3d161bd367ff63c6a8fb290fec0122d05.tar.bz2
rneovim-8674b0c3d161bd367ff63c6a8fb290fec0122d05.zip
syntax.c: Fix maybe-uninitialized warning (#7596)
When building in release mode, gcc generated a maybe-initialized warning in get_syn_options. The warning is both right and wrong; there is an execution path where the len variable is not initialized in the code: ... int len; ... for (fidx = ARRAY_SIZE(flagtab); --fidx >= 0; ) { p = flagtab[fidx].name; int i; for (i = 0, len = 0; p[i] != NUL; i += 2, ++len) if (arg[len] != p[i] && arg[len] != p[i + 1]) break; // <snip> } ... arg = skipwhite(arg + len); ... The initial for loop will not execute if ARRAY_SIZE(flagtab) == 0, and thus len will never be initialized. flagtab is a local-static variable, initialized to a long array of structured data, so ARRAY_SIZE(flagtab) can't be 0. However, gcc doesn't recognize ARRAY_SIZE(flagtab) as a constant. There are any number of reasons this could happen. In any case, the message can be fixed with a len=0 before the first for loop. In addition to the above warning, I've labeled flagtab and first_letters as const. They should never change.
-rw-r--r--src/nvim/syntax.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index 65490768c4..d28e996581 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -4009,10 +4009,10 @@ get_syn_options (
{
char_u *gname_start, *gname;
int syn_id;
- int len;
+ int len = 0;
char *p;
int fidx;
- static struct flag {
+ static const struct flag {
char *name;
int argtype;
int flags;
@@ -4035,7 +4035,7 @@ get_syn_options (
{"cCoOnNtTaAiInNsS", 1, 0},
{"cCoOnNtTaAiInNeEdDiInN", 2, 0},
{"nNeExXtTgGrRoOuUpP", 3, 0},};
- static char *first_letters = "cCoOkKeEtTsSgGdDfFnN";
+ static const char *const first_letters = "cCoOkKeEtTsSgGdDfFnN";
if (arg == NULL) /* already detected error */
return NULL;
@@ -4055,9 +4055,10 @@ get_syn_options (
for (fidx = ARRAY_SIZE(flagtab); --fidx >= 0; ) {
p = flagtab[fidx].name;
int i;
- for (i = 0, len = 0; p[i] != NUL; i += 2, ++len)
+ for (i = 0, len = 0; p[i] != NUL; i += 2, ++len) {
if (arg[len] != p[i] && arg[len] != p[i + 1])
break;
+ }
if (p[i] == NUL && (ascii_iswhite(arg[len])
|| (flagtab[fidx].argtype > 0
? arg[len] == '='