Skip to content

Commit

Permalink
Resolve c99 warnings
Browse files Browse the repository at this point in the history
'for' loop initial declarations are only allowed in C99 mode
  • Loading branch information
MaartenBent committed Jan 23, 2025
1 parent c90ed0d commit b4b4098
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 31 deletions.
49 changes: 25 additions & 24 deletions src/pcre2_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -5670,6 +5670,8 @@ BOOL previous_matched_char = FALSE;
BOOL reset_caseful = FALSE;
const uint8_t *cbits = cb->cbits;
uint8_t classbits[32];
int i;
uint32_t ui;

/* We can fish out the UTF setting once and for all into a BOOL, but we must
not do this for other options (e.g. PCRE2_EXTENDED) that may change dynamically
Expand Down Expand Up @@ -6116,9 +6118,9 @@ for (;; pptr++)
if (taboffset >= 0)
{
if (tabopt >= 0)
for (int i = 0; i < 32; i++) pbits[i] |= cbits[(int)i + taboffset];
for (i = 0; i < 32; i++) pbits[i] |= cbits[(int)i + taboffset];
else
for (int i = 0; i < 32; i++) pbits[i] &= ~cbits[(int)i + taboffset];
for (i = 0; i < 32; i++) pbits[i] &= ~cbits[(int)i + taboffset];
}

/* Now see if we need to remove any special characters. An option
Expand All @@ -6132,9 +6134,9 @@ for (;; pptr++)
being built and we are done. */

if (local_negate)
for (int i = 0; i < 32; i++) classbits[i] |= (uint8_t)(~pbits[i]);
for (i = 0; i < 32; i++) classbits[i] |= (uint8_t)(~pbits[i]);
else
for (int i = 0; i < 32; i++) classbits[i] |= pbits[i];
for (i = 0; i < 32; i++) classbits[i] |= pbits[i];

/* Every class contains at least one < 256 character. */

Expand Down Expand Up @@ -6173,22 +6175,22 @@ for (;; pptr++)
switch(escape)
{
case ESC_d:
for (int i = 0; i < 32; i++) classbits[i] |= cbits[i+cbit_digit];
for (i = 0; i < 32; i++) classbits[i] |= cbits[i+cbit_digit];
break;

case ESC_D:
should_flip_negation = TRUE;
for (int i = 0; i < 32; i++)
for (i = 0; i < 32; i++)
classbits[i] |= (uint8_t)(~cbits[i+cbit_digit]);
break;

case ESC_w:
for (int i = 0; i < 32; i++) classbits[i] |= cbits[i+cbit_word];
for (i = 0; i < 32; i++) classbits[i] |= cbits[i+cbit_word];
break;

case ESC_W:
should_flip_negation = TRUE;
for (int i = 0; i < 32; i++)
for (i = 0; i < 32; i++)
classbits[i] |= (uint8_t)(~cbits[i+cbit_word]);
break;

Expand All @@ -6200,12 +6202,12 @@ for (;; pptr++)
longer treat \s and \S specially. */

case ESC_s:
for (int i = 0; i < 32; i++) classbits[i] |= cbits[i+cbit_space];
for (i = 0; i < 32; i++) classbits[i] |= cbits[i+cbit_space];
break;

case ESC_S:
should_flip_negation = TRUE;
for (int i = 0; i < 32; i++)
for (i = 0; i < 32; i++)
classbits[i] |= (uint8_t)(~cbits[i+cbit_space]);
break;

Expand Down Expand Up @@ -6450,7 +6452,7 @@ for (;; pptr++)
if (negate_class && !xclass_has_prop)
{
/* Using 255 ^ instead of ~ avoids clang sanitize warning. */
for (int i = 0; i < 32; i++) classbits[i] = 255 ^ classbits[i];
for (i = 0; i < 32; i++) classbits[i] = 255 ^ classbits[i];
}
memcpy(code, classbits, 32);
code = class_uchardata + (32 / sizeof(PCRE2_UCHAR));
Expand All @@ -6476,7 +6478,7 @@ for (;; pptr++)
if (negate_class)
{
/* Using 255 ^ instead of ~ avoids clang sanitize warning. */
for (int i = 0; i < 32; i++) classbits[i] = 255 ^ classbits[i];
for (i = 0; i < 32; i++) classbits[i] = 255 ^ classbits[i];
}
memcpy(code, classbits, 32);
}
Expand Down Expand Up @@ -6550,7 +6552,7 @@ for (;; pptr++)
verbarglen = *(++pptr);
verbculen = 0;
tempcode = code++;
for (int i = 0; i < (int)verbarglen; i++)
for (i = 0; i < (int)verbarglen; i++)
{
meta = *(++pptr);
#ifdef SUPPORT_UNICODE
Expand Down Expand Up @@ -6600,7 +6602,6 @@ for (;; pptr++)
bravalue = OP_COND;
{
int count, index;
unsigned int i;
PCRE2_SPTR name;
named_group *ng = cb->named_groups;
uint32_t length = *(++pptr);
Expand All @@ -6614,7 +6615,7 @@ for (;; pptr++)
this name is duplicated. If it is not duplicated, we can handle it as a
numerical group. */

for (i = 0; i < cb->names_found; i++, ng++)
for (ui = 0; ui < cb->names_found; ui++, ng++)
{
if (length == ng->length &&
PRIV(strncmp)(name, ng->name, length) == 0)
Expand All @@ -6635,18 +6636,18 @@ for (;; pptr++)
dealing with R<digits>, which is treated as a recursion test by number.
*/

if (i >= cb->names_found)
if (ui >= cb->names_found)
{
groupnumber = 0;
if (meta == META_COND_RNUMBER)
{
for (i = 1; i < length; i++)
for (ui = 1; ui < length; ui++)
{
groupnumber = groupnumber * 10 + name[i] - CHAR_0;
groupnumber = groupnumber * 10 + name[ui] - CHAR_0;
if (groupnumber > MAX_GROUP_NUMBER)
{
*errorcodeptr = ERR61;
cb->erroroffset = offset + i;
cb->erroroffset = offset + ui;
return 0;
}
}
Expand Down Expand Up @@ -7036,7 +7037,7 @@ for (;; pptr++)
this name is duplicated. */

groupnumber = 0;
for (unsigned int i = 0; i < cb->names_found; i++, ng++)
for (ui = 0; ui < cb->names_found; ui++, ng++)
{
if (length == ng->length &&
PRIV(strncmp)(name, ng->name, length) == 0)
Expand Down Expand Up @@ -7392,7 +7393,7 @@ for (;; pptr++)
*lengthptr += delta;
}

else for (int i = 0; i < replicate; i++)
else for (i = 0; i < replicate; i++)
{
memcpy(code, previous, CU2BYTES(1 + LINK_SIZE));
previous = code;
Expand Down Expand Up @@ -7571,7 +7572,7 @@ for (;; pptr++)
reqcu = firstcu;
reqcuflags = firstcuflags;
}
for (uint32_t i = 1; i < repeat_min; i++)
for (ui = 1; ui < repeat_min; ui++)
{
memcpy(code, previous, CU2BYTES(len));
code += len;
Expand Down Expand Up @@ -7613,14 +7614,14 @@ for (;; pptr++)

/* This is compiling for real */

else for (uint32_t i = repeat_max; i >= 1; i--)
else for (ui = repeat_max; ui >= 1; ui--)
{
*code++ = OP_BRAZERO + repeat_type;

/* All but the final copy start a new nesting, maintaining the
chain of brackets outstanding. */

if (i != 1)
if (ui != 1)
{
int linkoffset;
*code++ = OP_BRA;
Expand Down
4 changes: 2 additions & 2 deletions src/pcre2_dfa_match.c
Original file line number Diff line number Diff line change
Expand Up @@ -2959,8 +2959,8 @@ for (;;)
/* Check for repeating a recursion without advancing the subject
pointer or last used character. This should catch convoluted mutual
recursions. (Some simple cases are caught at compile time.) */

for (dfa_recursion_info *ri = mb->recursive;
dfa_recursion_info* ri;
for (ri = mb->recursive;
ri != NULL;
ri = ri->prevrec)
{
Expand Down
7 changes: 4 additions & 3 deletions src/pcre2_script_run.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ every script, as opposed to the maps in ucd_script_sets, which only have bits
for scripts less than ucp_Unknown - those that appear in script extension
lists. */

for (int i = 0; i < FULL_MAPSIZE; i++) require_map[i] = 0;
int i;
for (i = 0; i < FULL_MAPSIZE; i++) require_map[i] = 0;

/* Scan strings of two or more characters, checking the Unicode characteristics
of each code point. There is special code for scripts that can be combined with
Expand Down Expand Up @@ -245,7 +246,7 @@ for (;;)
case SCRIPT_MAP:
OK = FALSE;

for (int i = 0; i < FULL_MAPSIZE; i++)
for (i = 0; i < FULL_MAPSIZE; i++)
{
if ((require_map[i] & map[i]) != 0)
{
Expand Down Expand Up @@ -282,7 +283,7 @@ for (;;)
allowed scripts for this character. */

default:
for (int i = 0; i < FULL_MAPSIZE; i++) require_map[i] &= map[i];
for (i = 0; i < FULL_MAPSIZE; i++) require_map[i] &= map[i];
break;
}

Expand Down
4 changes: 2 additions & 2 deletions src/pcre2_study.c
Original file line number Diff line number Diff line change
Expand Up @@ -1123,8 +1123,8 @@ do
ncode += 1 + LINK_SIZE;

/* Skip irrelevant items */

for (BOOL done = FALSE; !done;)
BOOL done;
for (done = FALSE; !done;)
{
switch (*ncode)
{
Expand Down

0 comments on commit b4b4098

Please sign in to comment.