Skip to content

Commit

Permalink
Prevent GCC warnings
Browse files Browse the repository at this point in the history
```
regexec.c: In function ‘reset_match_cache’:
regexec.c:1259:56: warning: suggest parentheses around ‘-’ inside ‘<<’ [-Wparentheses]
 1259 |     match_cache[k1 >> 3] &= ((1 << (8 - (k2 & 7) - 1)) - 1 << ((k2 & 7) + 1)) | ((1 << (k1 & 7)) - 1);
      |                              ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
regexec.c:1269:60: warning: suggest parentheses around ‘-’ inside ‘<<’ [-Wparentheses]
 1269 |         match_cache[k2 >> 3] &= ((1 << (8 - (k2 & 7) - 1)) - 1 << ((k2 & 7) + 1));
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
regexec.c: In function ‘find_cache_index_table’:
regexec.c:1192:11: warning: ‘m’ may be used uninitialized [-Wmaybe-uninitialized]
 1192 |   if (!(0 <= m && m < num_cache_table && table[m].addr == p)) {
      |         ~~^~~~
regexec.c: In function ‘match_at’:
regexec.c:1238:12: warning: ‘m1’ is used uninitialized [-Wuninitialized]
 1238 |   if (table[m1].addr < pbegin && m1 + 1 < num_cache_table) m1++;
      |            ^
regexec.c:1218:39: note: ‘m1’ was declared here
 1218 |   int l = 0, r = num_cache_table - 1, m1, m2;
      |                                       ^~
regexec.c:1239:12: warning: ‘m2’ is used uninitialized [-Wuninitialized]
 1239 |   if (table[m2].addr > pend && m2 - 1 > 0) m2--;
      |            ^
regexec.c:1218:43: note: ‘m2’ was declared here
 1218 |   int l = 0, r = num_cache_table - 1, m1, m2;
      |                                           ^~
```
  • Loading branch information
mame committed Nov 9, 2022
1 parent ff5dba8 commit 537286d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions regexec.c
Expand Up @@ -1175,7 +1175,7 @@ stack_double(OnigStackType** arg_stk_base, OnigStackType** arg_stk_end,

static int find_cache_index_table(regex_t* reg, OnigStackType *stk, OnigStackIndex *repeat_stk, OnigCacheIndex* table, int num_cache_table, UChar* p)
{
int l = 0, r = num_cache_table - 1, m;
int l = 0, r = num_cache_table - 1, m = 0;
OnigCacheIndex* item;
OnigRepeatRange* range;
OnigStackType *stkp;
Expand Down Expand Up @@ -1215,7 +1215,7 @@ static int find_cache_index_table(regex_t* reg, OnigStackType *stk, OnigStackInd
}

static void reset_match_cache(regex_t* reg, UChar* pbegin, UChar* pend, int pos, uint8_t* match_cache, OnigCacheIndex *table, int num_cache_size, int num_cache_table) {
int l = 0, r = num_cache_table - 1, m1, m2;
int l = 0, r = num_cache_table - 1, m1 = 0, m2 = 0;
int is_inc = *pend == OP_REPEAT_INC || *pend == OP_REPEAT_INC_NG;
OnigCacheIndex *item1, *item2;
int k1, k2;
Expand Down Expand Up @@ -1256,7 +1256,7 @@ static void reset_match_cache(regex_t* reg, UChar* pbegin, UChar* pend, int pos,
k2 += base;

if ((k1 >> 3) == (k2 >> 3)) {
match_cache[k1 >> 3] &= ((1 << (8 - (k2 & 7) - 1)) - 1 << ((k2 & 7) + 1)) | ((1 << (k1 & 7)) - 1);
match_cache[k1 >> 3] &= (((1 << (8 - (k2 & 7) - 1)) - 1) << ((k2 & 7) + 1)) | ((1 << (k1 & 7)) - 1);
} else {
int i = k1 >> 3;
if (k1 & 7) {
Expand All @@ -1266,7 +1266,7 @@ static void reset_match_cache(regex_t* reg, UChar* pbegin, UChar* pend, int pos,
if (i < (k2 >> 3)) {
xmemset(&match_cache[i], 0, (k2 >> 3) - i);
if (k2 & 7) {
match_cache[k2 >> 3] &= ((1 << (8 - (k2 & 7) - 1)) - 1 << ((k2 & 7) + 1));
match_cache[k2 >> 3] &= (((1 << (8 - (k2 & 7) - 1)) - 1) << ((k2 & 7) + 1));
}
}
}
Expand Down

0 comments on commit 537286d

Please sign in to comment.