GCC 10 warnings

Create issue
Issue #386 resolved
Boris Staletic created an issue

Hi. When compiling the latest commit, with gcc 10, I see some warnings.

Unused variable

regex_3/_regex.c: In function ‘folded_char_at’:
regex_3/_regex.c:9897:9: warning: variable ‘folded_len’ set but not used [-Wunused-but-set-variable]
 9897 |     int folded_len;
      |         ^~~~~~~~~~

This one should be straight forward. We can just ignore the return value.

Reading an uninitialized variable

regex_3/_regex.c: In function ‘fuzzy_match_string_fld’:
regex_3/_regex.c:10580:10: warning: ‘data.new_text_pos’ may be used uninitialized in this function [-Wmaybe-uninitialized]
10580 |     if (!record_fuzzy(state, data.fuzzy_type, data.fuzzy_type == RE_FUZZY_DEL ?
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10581 |       data.new_text_pos : data.new_text_pos - data.step))
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
regex_3/_regex.c: In function ‘fuzzy_match_group_fld’:
regex_3/_regex.c:10815:10: warning: ‘data.new_text_pos’ may be used uninitialized in this function [-Wmaybe-uninitialized]
10815 |     if (!record_fuzzy(state, data.fuzzy_type, data.fuzzy_type == RE_FUZZY_DEL ?
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10816 |       data.new_text_pos : data.new_text_pos - data.step))
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
regex_3/_regex.c: In function ‘basic_match’:
regex_3/_regex.c:10921:10: warning: ‘data.new_text_pos’ may be used uninitialized in this function [-Wmaybe-uninitialized]
10921 |     if (!record_fuzzy(state, data.fuzzy_type, data.fuzzy_type == RE_FUZZY_DEL ?
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10922 |       data.new_text_pos : data.new_text_pos - data.step))
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
regex_3/_regex.c:10835:18: note: ‘data.new_text_pos’ was declared here
10835 |     RE_FuzzyData data;
      |                  ^~~~
regex_3/_regex.c:10680:10: warning: ‘data.new_text_pos’ may be used uninitialized in this function [-Wmaybe-uninitialized]
10680 |     if (!record_fuzzy(state, data.fuzzy_type, data.fuzzy_type == RE_FUZZY_DEL ?
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10681 |       data.new_text_pos : data.new_text_pos - data.step))
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
regex_3/_regex.c:10599:18: note: ‘data.new_text_pos’ was declared here
10599 |     RE_FuzzyData data;
      |                  ^~~~

In each of these functions, data.new_text_pos is not initialized, but a local variable called new_text_pos is. Both data.new_text_pos and new_text_pos are used.

-Wmissing-braces in re_all_cases_table_4[] andre_full_folding_table_4[]

re_full_folding_table_4[] has the type RE_FullCaseFolding[], whose elements are struct { uint16[] };. To silence the warning, the generated array should be

static RE_FullCaseFolding re_full_folding_table_4[] = {  { {a, b, c} }, { {q, w, e} }  };

Outer-most braces for the entire array, “middle” ones for the struct and inner-most for the uint16[].

Similarly, re_all_cases_table_4[] should look like this:

static RE_AllCases re_all_cases_table_4[] = {  {a, {b, c}}, {q, {w, e}}  };

This would need a change in build_regex_unicode.py and the patch would look like this:

diff --git a/tools/build_regex_unicode.py b/tools/build_regex_unicode.py
index da53640..a911615 100644
--- a/tools/build_regex_unicode.py
+++ b/tools/build_regex_unicode.py
@@ -1074,7 +1074,7 @@ def generate_all_cases(unicode_data, c_file):
     max_columns = max(len(value) for value in others_dict)

     max_width = max(len(str(item)) for value in others_dict for item in value)
-    fmt = '    {{' + ', '.join(['{:%d}' % max_width] * max_columns) + '}},\n'
+    fmt = '    {{{:%d}, {{' % max_width + ', '.join(['{:%d}' % max_width] * (max_columns -1)) + '}}}},\n'

     lines = []

@@ -1245,8 +1245,8 @@ def generate_full_case_folding(unicode_data, c_file):
     max_width = max(len(str(item)) for value in value_dict for item in value)
     rows = [(value + (0, ) * max_folded)[ : max_folded] for value in
       sorted(value_dict, key=value_dict.get)]
-    fmt = ('    {{' + ', '.join(['{:%d}' % max_width] * max_folded) +
-      '}},\n').format
+    fmt = ('    {{{{' + ', '.join(['{:%d}' % max_width] * max_folded) +
+      '}}}},\n').format
     lines = []

This last one could also be silenced with -Wno-missing-braces.

Comments (1)

  1. Log in to comment