From d0345459737e9f4ee436fa3a19a076ac681db2a5 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 16 Aug 2016 03:04:26 -0700 Subject: [PATCH 1/2] dfa: avoid uninitialized constants Some compilers warn about 'static int const x;' on the grounds that X should have an initializer. Instead of worrying about this, rewrite to avoid this sort of thing. * src/dfa.c (emptyset): New function. (parse_bracket_exp): Use it instead of 'equal' and a zero constant. * src/dfasearch.c (struct patterns): Remove tag 'patterns'. (patterns0): Remove zero constant. (GEAcompile): Use memset instead of the zero constant. --- src/dfa.c | 13 +++++++++++-- src/dfasearch.c | 8 +++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/dfa.c b/src/dfa.c index b64a176..f970766 100644 --- a/src/dfa.c +++ b/src/dfa.c @@ -608,6 +608,16 @@ equal (charclass const s1, charclass const s2) return memcmp (s1, s2, sizeof (charclass)) == 0; } +static bool +emptyset (charclass const s) +{ + charclass_word w = 0; + int i; + for (i = 0; i < CHARCLASS_WORDS; i++) + w |= s[i]; + return w == 0; +} + /* Ensure that the array addressed by PTR holds at least NITEMS + (PTR || !NITEMS) items. Either return PTR, or reallocate the array and return its new address. Although PTR may be null, the returned @@ -1184,9 +1194,8 @@ parse_bracket_exp (void) if (dfa->multibyte) { - static charclass const zeroclass; work_mbc->invert = invert; - work_mbc->cset = equal (ccl, zeroclass) ? -1 : charclass_index (ccl); + work_mbc->cset = emptyset (ccl) ? -1 : charclass_index (ccl); return MBCSET; } diff --git a/src/dfasearch.c b/src/dfasearch.c index 9a523c8..222232c 100644 --- a/src/dfasearch.c +++ b/src/dfasearch.c @@ -38,15 +38,13 @@ static kwset_t kwset; static struct dfa *dfa; /* The Regex compiled patterns. */ -static const struct patterns +static struct { /* Regex compiled regexp. */ struct re_pattern_buffer regexbuf; struct re_registers regs; /* This is here on account of a BRAIN-DEAD address@hidden library interface in regex.c. */ -} patterns0; - -static struct patterns *patterns; +} *patterns; static size_t pcount; /* Number of compiled fixed strings known to exactly match the regexp. @@ -153,7 +151,7 @@ GEAcompile (char const *pattern, size_t size, reg_syntax_t syntax_bits) } patterns = xnrealloc (patterns, pcount + 1, sizeof *patterns); - patterns[pcount] = patterns0; + memset (&patterns[pcount], 0, sizeof patterns[pcount]); char const *err = re_compile_pattern (p, len, &(patterns[pcount].regexbuf)); -- 2.7.4