Move variable declarations closer to first use Keep the safe declaration-placement changes from the refreshed branch. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
diff --git a/src/pcre2_auto_possess.c b/src/pcre2_auto_possess.c index 6a4db00..b5b8793 100644 --- a/src/pcre2_auto_possess.c +++ b/src/pcre2_auto_possess.c
@@ -881,10 +881,8 @@ else { - uint32_t leftop, rightop; - - leftop = base_list[0]; - rightop = list[0]; + uint32_t leftop = base_list[0]; + uint32_t rightop = list[0]; #ifdef SUPPORT_UNICODE accepted = FALSE; // Always set in non-unicode case. @@ -896,7 +894,6 @@ } else if (rightop == OP_PROP || rightop == OP_NOTPROP) { - int n; const uint8_t *p; BOOL same = leftop == rightop; BOOL lisprop = leftop == OP_PROP; @@ -912,7 +909,7 @@ ... see comments below */ - n = propposstab[base_list[2]][list[2]]; + int n = propposstab[base_list[2]][list[2]]; switch (n) { case 0:
diff --git a/src/pcre2_compile.c b/src/pcre2_compile.c index bc4aaf1..09588c9 100644 --- a/src/pcre2_compile.c +++ b/src/pcre2_compile.c
@@ -1260,12 +1260,9 @@ PCRE2_EXP_DEFN pcre2_code *PCRE2_CALL_CONVENTION pcre2_code_copy(const pcre2_code *code) { - PCRE2_SIZE *ref_count; - pcre2_code *newcode; - if (code == NULL) return NULL; - newcode = code->memctl.malloc(code->blocksize, code->memctl.memory_data); + pcre2_code *newcode = code->memctl.malloc(code->blocksize, code->memctl.memory_data); if (newcode == NULL) return NULL; memcpy(newcode, code, code->blocksize); @@ -1277,7 +1274,7 @@ if ((code->flags & PCRE2_DEREF_TABLES) != 0) { PCRE2_ASSERT(code->tables != NULL); - ref_count = (PCRE2_SIZE *)(code->tables + TABLES_LENGTH); + PCRE2_SIZE *ref_count = (PCRE2_SIZE *)(code->tables + TABLES_LENGTH); (*ref_count)++; } @@ -1297,20 +1294,16 @@ PCRE2_EXP_DEFN pcre2_code *PCRE2_CALL_CONVENTION pcre2_code_copy_with_tables(const pcre2_code *code) { - PCRE2_SIZE *ref_count; - pcre2_code *newcode; - uint8_t *newtables; - if (code == NULL) return NULL; PCRE2_ASSERT(code->tables != NULL); - newcode = code->memctl.malloc(code->blocksize, code->memctl.memory_data); + pcre2_code *newcode = code->memctl.malloc(code->blocksize, code->memctl.memory_data); if (newcode == NULL) return NULL; memcpy(newcode, code, code->blocksize); newcode->executable_jit = NULL; - newtables = code->memctl.malloc(TABLES_LENGTH + sizeof(PCRE2_SIZE), code->memctl.memory_data); + uint8_t *newtables = code->memctl.malloc(TABLES_LENGTH + sizeof(PCRE2_SIZE), code->memctl.memory_data); if (newtables == NULL) { code->memctl.free((void *)newcode, code->memctl.memory_data); @@ -1318,7 +1311,7 @@ } memcpy(newtables, code->tables, TABLES_LENGTH); - ref_count = (PCRE2_SIZE *)(newtables + TABLES_LENGTH); + PCRE2_SIZE *ref_count = (PCRE2_SIZE *)(newtables + TABLES_LENGTH); *ref_count = 1; newcode->tables = newtables; @@ -1495,7 +1488,6 @@ int *errorcodeptr) { PCRE2_SPTR p = *ptrptr; - PCRE2_SPTR pp; BOOL yield = FALSE; BOOL had_minimum = FALSE; int32_t min = 0; @@ -1509,7 +1501,7 @@ such as "X{123456ABC" would incorrectly give a "number too big in quantifier" error. */ - pp = p; + PCRE2_SPTR pp = p; if (pp < ptrend && IS_DIGIT(*pp)) { had_minimum = TRUE; @@ -1940,7 +1932,6 @@ if (cb == NULL) { - PCRE2_SPTR p; /* Substitution strings */ if (*ptr != CHAR_LESS_THAN_SIGN) { @@ -1948,7 +1939,7 @@ break; } - p = ptr + 1; + PCRE2_SPTR p = ptr + 1; if (!read_number(&p, ptrend, -1, MAX_GROUP_NUMBER, ERR61, &s, errorcodeptr)) { @@ -2512,7 +2503,6 @@ get_ucp(PCRE2_SPTR *ptrptr, BOOL utf, BOOL *negptr, uint16_t *ptypeptr, uint16_t *pdataptr, int *errorcodeptr, compile_block *cb) { - uint32_t c; ptrdiff_t i; PCRE2_SIZE bot, top; PCRE2_SPTR ptr = *ptrptr; @@ -2526,6 +2516,7 @@ if (ptr >= cb->end_pattern) goto ERROR_RETURN; + uint32_t c; GETCHARINCTEST(c, ptr); *negptr = FALSE; @@ -2676,9 +2667,8 @@ while (bot < top) { - int r; i = (bot + top) >> 1; - r = PRIV(strcmp_c8)(name, PRIV(utt_names) + PRIV(utt)[i].name_offset); + int r = PRIV(strcmp_c8)(name, PRIV(utt_names) + PRIV(utt)[i].name_offset); /* When a matching property is found, some extra checking is needed when the \p{xx:yy} syntax is used and xx is either sc or scx. */ @@ -2773,8 +2763,7 @@ check_posix_syntax(PCRE2_SPTR ptr, PCRE2_SPTR ptrend, PCRE2_SPTR *endptr) { /* Don't combine these lines; the Solaris cc compiler warns about "non-constant" initializer. */ - PCRE2_UCHAR terminator; - terminator = *ptr++; + PCRE2_UCHAR terminator = *ptr++; for (; ptrend - ptr >= 2; ptr++) { @@ -2894,11 +2883,11 @@ #ifdef SUPPORT_UNICODE if (utf && is_group) { - uint32_t c, type; PCRE2_SPTR p = ptr; + uint32_t c; GETCHARINC(c, p); // Peek at next character - type = UCD_CHARTYPE(c); + uint32_t type = UCD_CHARTYPE(c); if (type == ucp_Nd) { @@ -3270,7 +3259,6 @@ max_parsed_pattern(PCRE2_SPTR ptr, PCRE2_SPTR ptrend, BOOL utf, uint32_t options) { PCRE2_SIZE big32count = 0; - ptrdiff_t parsed_size_needed; /* When PCRE2_AUTO_CALLOUT is not set, in all but one case the number of unsigned 32-bit ints written out to the parsed pattern is bounded by the length @@ -3291,7 +3279,7 @@ (void)utf; // Avoid compiler warning #endif - parsed_size_needed = (ptrend - ptr) + big32count; + ptrdiff_t parsed_size_needed = (ptrend - ptr) + big32count; /* When PCRE2_AUTO_CALLOUT is set we have to assume a numerical callout (4 elements) for each character. This is overkill, but memory is plentiful these @@ -3448,10 +3436,8 @@ named_group *ng; nest_save *top_nest, *end_nests; #ifdef PCRE2_DEBUG - uint32_t *parsed_pattern_check; ptrdiff_t parsed_pattern_extra = 0; ptrdiff_t parsed_pattern_extra_check = 0; - PCRE2_SPTR ptr_check; #endif PCRE2_ASSERT(parsed_pattern != NULL); @@ -3471,8 +3457,8 @@ } #ifdef PCRE2_DEBUG - parsed_pattern_check = parsed_pattern; - ptr_check = ptr; + uint32_t *parsed_pattern_check = parsed_pattern; + PCRE2_SPTR ptr_check = ptr; #endif /* If the pattern is actually a literal string, process it separately to avoid @@ -3523,13 +3509,10 @@ while (ptr < ptrend) { - int prev_expect_cond_assert; uint32_t min_repeat = 0, max_repeat = 0; uint32_t set, unset, *optset; uint32_t xset, xunset, *xoptset; uint32_t terminator; - uint32_t prev_meta_quantifier; - BOOL prev_okquantifier; PCRE2_SPTR tempptr; PCRE2_SIZE offset; @@ -3880,14 +3863,14 @@ /* Remember whether we are expecting a conditional assertion, and set the default for this item. */ - prev_expect_cond_assert = expect_cond_assert; + int prev_expect_cond_assert = expect_cond_assert; expect_cond_assert = 0; /* Remember quantification status for the previous significant item, then set default for this item. */ - prev_okquantifier = okquantifier; - prev_meta_quantifier = meta_quantifier; + BOOL prev_okquantifier = okquantifier; + uint32_t prev_meta_quantifier = meta_quantifier; okquantifier = FALSE; meta_quantifier = 0; @@ -4357,7 +4340,6 @@ check_posix_syntax(ptr, ptrend, &tempptr)) { BOOL posix_negate = FALSE; - int posix_class; /* Perl treats a hyphen before a POSIX class as a literal, not the start of a range. However, it gives a warning in its warning mode. PCRE @@ -4408,7 +4390,7 @@ ptr++; } - posix_class = check_posix_name(ptr, (int)(tempptr - ptr)); + int posix_class = check_posix_name(ptr, (int)(tempptr - ptr)); ptr = tempptr + 2; if (posix_class < 0) { @@ -5113,8 +5095,6 @@ else if (CHMAX_255(c) && (cb->ctypes[c] & ctype_lcletter) != 0) { - uint32_t meta; - vn = alasnames; if (!read_name(&ptr, ptrend, utf, 0, &offset, &name, &namelen, &errorcode, cb)) goto FAILED; @@ -5144,7 +5124,7 @@ /* Check for expecting an assertion condition. If so, only atomic lookaround assertions are valid. */ - meta = alasmeta[i].meta; + uint32_t meta = alasmeta[i].meta; if (prev_expect_cond_assert > 0 && (meta < META_LOOKAHEAD || meta > META_LOOKBEHINDNOT)) { errorcode = ERR28; // Atomic assertion expected @@ -5732,7 +5712,6 @@ if (*ptr != CHAR_RIGHT_PARENTHESIS && !IS_DIGIT(*ptr)) { - PCRE2_SIZE calloutlength; PCRE2_SPTR startptr = ptr; delimiter = 0; @@ -5767,7 +5746,7 @@ break; } - calloutlength = (PCRE2_SIZE)(ptr - startptr); + PCRE2_SIZE calloutlength = (PCRE2_SIZE)(ptr - startptr); if (calloutlength > UINT32_MAX) { errorcode = ERR72; @@ -6590,9 +6569,7 @@ for (;; pptr++) { BOOL possessive_quantifier; - BOOL note_group_empty; uint32_t mclength; - uint32_t skipunits; uint32_t subreqcu, subfirstcu; uint32_t groupnumber; uint32_t verbarglen, verbculen; @@ -6681,8 +6658,8 @@ previous_matched_char = matched_char; matched_char = FALSE; - note_group_empty = FALSE; - skipunits = 0; // Default value for most subgroups + BOOL note_group_empty = FALSE; + uint32_t skipunits = 0; // Default value for most subgroups switch (meta) { @@ -7136,13 +7113,11 @@ if (lengthptr != NULL) { uint32_t i; - PCRE2_SPTR name; - named_group *ng; uint32_t *start_pptr = pptr; uint32_t length = *(++pptr); GETPLUSOFFSET(offset, pptr); - name = cb->start_pattern + offset; + PCRE2_SPTR name = cb->start_pattern + offset; /* In the first pass, the names generated in the pre-pass are available, but the main name table has not yet been created. Scan the list of names @@ -7150,7 +7125,7 @@ this name is duplicated. If it is not duplicated, we can handle it as a numerical group. */ - ng = PRIV(compile_find_named_group)(name, length, cb); + named_group *ng = PRIV(compile_find_named_group)(name, length, cb); if (ng == NULL) { @@ -7226,7 +7201,6 @@ /* Otherwise lengthptr equals to NULL, which is the second phase of compilation. */ int count, index; - named_group *ng; /* Generate code using the data collected in the pre-processing phase. */ @@ -7249,7 +7223,7 @@ goto GROUP_PROCESS_NOTE_EMPTY; } - ng = cb->named_groups + pptr[1]; + named_group *ng = cb->named_groups + pptr[1]; count = 0; // Values for first pass (avoids compiler warning) index = 0; @@ -7616,19 +7590,17 @@ case META_RECURSE_BYNAME: { int count, index; - PCRE2_SPTR name; - named_group *ng; uint32_t length = *(++pptr); GETPLUSOFFSET(offset, pptr); - name = cb->start_pattern + offset; + PCRE2_SPTR name = cb->start_pattern + offset; /* In the first pass, the names generated in the pre-pass are available, but the main name table has not yet been created. Scan the list of names generated in the pre-pass in order to get a number and whether or not this name is duplicated. */ - ng = PRIV(compile_find_named_group)(name, length, cb); + named_group *ng = PRIV(compile_find_named_group)(name, length, cb); if (ng == NULL) { @@ -7724,8 +7696,6 @@ else { - PCRE2_SPTR pp; - uint32_t delimiter; uint32_t length = pptr[3]; PCRE2_UCHAR *callout_string = code + (1 + 4 * LINK_SIZE); @@ -7735,8 +7705,8 @@ pptr += 3; GETPLUSOFFSET(offset, pptr); // Offset to string in pattern - pp = cb->start_pattern + offset; - delimiter = *callout_string++ = *pp++; + PCRE2_SPTR pp = cb->start_pattern + offset; + uint32_t delimiter = *callout_string++ = *pp++; if (delimiter == CHAR_LEFT_CURLY_BRACKET) delimiter = CHAR_RIGHT_CURLY_BRACKET; PUT(code, 1 + 3 * LINK_SIZE, (int)(offset + 1)); // One after delimiter @@ -8136,7 +8106,6 @@ else { - int linkoffset; (void)memmove(previous + 2 + LINK_SIZE, previous, CU2BYTES(len)); code += 2 + LINK_SIZE; *previous++ = OP_BRAZERO + repeat_type; @@ -8145,7 +8114,7 @@ /* We chain together the bracket link offset fields that have to be filled in later when the ends of the brackets are reached. */ - linkoffset = (bralink == NULL) ? 0 : (int)(previous - bralink); + int linkoffset = (bralink == NULL) ? 0 : (int)(previous - bralink); bralink = previous; PUTINC(previous, 0, linkoffset); } @@ -8245,9 +8214,8 @@ if (i != 1) { - int linkoffset; *code++ = OP_BRA; - linkoffset = (bralink == NULL) ? 0 : (int)(code - bralink); + int linkoffset = (bralink == NULL) ? 0 : (int)(code - bralink); bralink = code; PUTINC(code, 0, linkoffset); } @@ -8261,10 +8229,9 @@ while (bralink != NULL) { - int oldlinkoffset; int linkoffset = (int)(code - bralink + 1); PCRE2_UCHAR *bra = code - linkoffset; - oldlinkoffset = GET(bra, 1); + int oldlinkoffset = GET(bra, 1); bralink = (oldlinkoffset == 0) ? NULL : bralink - oldlinkoffset; *code++ = OP_KET; PUTINC(code, 0, linkoffset); @@ -8399,7 +8366,6 @@ { int prop_type, prop_value; - PCRE2_UCHAR *oldcode; if (repeat_max == 1 && repeat_min == 1) goto END_REPEAT; @@ -8426,7 +8392,7 @@ op_previous. If prop_type/value are not negative, we have a property character type in op_previous. */ - oldcode = code; // Save where we were + PCRE2_UCHAR *oldcode = code; // Save where we were code = previous; // Usually overwrite previous item /* If the maximum is zero then the minimum must also be zero; Perl allows @@ -9146,7 +9112,6 @@ PCRE2_UCHAR *code = *codeptr; PCRE2_UCHAR *last_branch = code; PCRE2_UCHAR *start_bracket = code; - BOOL lookbehind; open_capitem capitem; int capnumber = 0; int okreturn = 1; @@ -9155,7 +9120,6 @@ uint32_t lookbehindlength; uint32_t lookbehindminlength; uint32_t firstcuflags, reqcuflags; - PCRE2_SIZE length; branch_chain bc; /* If set, call the external function that checks for stack availability. */ @@ -9183,12 +9147,12 @@ start and end of each alternative, because compiled items are discarded during the pre-compile phase so that the workspace is not exceeded. */ - length = 2 + 2 * LINK_SIZE + skipunits; + PCRE2_SIZE length = 2 + 2 * LINK_SIZE + skipunits; /* Remember if this is a lookbehind assertion, and if it is, save its length and skip over the pattern offset. */ - lookbehind = *code == OP_ASSERTBACK || *code == OP_ASSERTBACK_NOT || *code == OP_ASSERTBACK_NA; + BOOL lookbehind = *code == OP_ASSERTBACK || *code == OP_ASSERTBACK_NOT || *code == OP_ASSERTBACK_NA; if (lookbehind) { @@ -10422,15 +10386,13 @@ case META_RECURSE_BYNAME: { - PCRE2_SPTR name; BOOL is_dupname = FALSE; - named_group *ng; uint32_t meta_code = META_CODE(*pptr); uint32_t length = *(++pptr); GETPLUSOFFSET(offset, pptr); - name = cb->start_pattern + offset; - ng = PRIV(compile_find_named_group)(name, length, cb); + PCRE2_SPTR name = cb->start_pattern + offset; + named_group *ng = PRIV(compile_find_named_group)(name, length, cb); if (ng == NULL) { @@ -10702,10 +10664,9 @@ do { - int branchlength, branchminlength; - *pptrptr += 1; - branchlength = get_branchlength(pptrptr, &branchminlength, errcodeptr, lcptr, recurses, cb); + int branchminlength; + int branchlength = get_branchlength(pptrptr, &branchminlength, errcodeptr, lcptr, recurses, cb); if (branchlength < 0) { @@ -11771,9 +11732,9 @@ for (rcode = find_recurse(codestart, utf); rcode != NULL; rcode = find_recurse(rcode + 1 + LINK_SIZE, utf)) { - int p, groupnumber; + int p; - groupnumber = (int)GET(rcode, 1); + int groupnumber = (int)GET(rcode, 1); if (groupnumber == 0) { rgroup = codestart; @@ -11880,7 +11841,6 @@ if ((optim_flags & PCRE2_OPTIM_START_OPTIMIZE) != 0) { int minminlength = 0; // For minimal minlength from first/required CU - int study_rc; /* If we do not have a first code unit, see if there is one that is asserted (these are not saved during the compile because they can cause conflicts with @@ -12005,7 +11965,7 @@ /* Study the compiled pattern to set up information such as a bitmap of starting code units and a minimum matching length. */ - study_rc = PRIV(study)(re); + int study_rc = PRIV(study)(re); /* LCOV_EXCL_START */ if (study_rc != 0) {
diff --git a/src/pcre2_compile_cgroup.c b/src/pcre2_compile_cgroup.c index 3b79b1d..e77cc20 100644 --- a/src/pcre2_compile_cgroup.c +++ b/src/pcre2_compile_cgroup.c
@@ -58,11 +58,9 @@ uint16_t PRIV(compile_get_hash_from_name)(PCRE2_SPTR name, uint32_t length) { - uint16_t hash; - PCRE2_ASSERT(length > 0); - hash = (uint16_t)((name[0] & 0x7f) | ((name[length - 1] & 0xff) << 7)); + uint16_t hash = (uint16_t)((name[0] & 0x7f) | ((name[length - 1] & 0xff) << 7)); PCRE2_ASSERT(hash <= NAMED_GROUP_HASH_MASK); return hash; } @@ -214,7 +212,6 @@ int *errorcodeptr, compile_block *cb) { uint32_t i, groupnumber; - int count; PCRE2_UCHAR *slot = cb->name_table; /* Find the first entry in the table */ @@ -243,7 +240,7 @@ backref map and maximum back reference as we do. */ *indexptr = i; - count = 0; + int count = 0; for (;;) { @@ -368,14 +365,12 @@ PRIV(compile_parse_scan_substr_args)(uint32_t *pptr, int *errorcodeptr, compile_block *cb, PCRE2_SIZE *lengthptr) { - uint8_t *captures; uint8_t *capture_ptr; uint8_t bit; PCRE2_SPTR name; named_group *ng; named_group *end = cb->named_groups + cb->names_found; BOOL all_found; - size_t size; PCRE2_ASSERT(*pptr == META_OFFSET); if (PRIV(compile_process_capture_list)(pptr - 1, 0, errorcodeptr, cb) == 0) @@ -383,8 +378,8 @@ /* Align to bytes. Since the highest capture can be equal to bracount, +1 is added before the aligning. */ - size = (cb->bracount + 1 + 7) >> 3; - captures = (uint8_t *)cb->cx->memctl.malloc(size, cb->cx->memctl.memory_data); + size_t size = (cb->bracount + 1 + 7) >> 3; + uint8_t *captures = (uint8_t *)cb->cx->memctl.malloc(size, cb->cx->memctl.memory_data); if (captures == NULL) { *errorcodeptr = ERR21; @@ -523,10 +518,6 @@ named_group *ng; named_group *end = cb->named_groups + cb->names_found; recurse_arguments *args; - uint16_t *captures; - uint16_t *current; - uint16_t *captures_end; - uint16_t tmp; /* Process all arguments, compute the required size. */ @@ -560,7 +551,7 @@ /* Create the capture list size. */ - captures = (uint16_t *)(args + 1); + uint16_t *captures = (uint16_t *)(args + 1); while (TRUE) { @@ -615,7 +606,7 @@ for (i = size - 1; i > 0; i--) { - tmp = captures[0]; + uint16_t tmp = captures[0]; captures[0] = captures[i]; captures[i] = tmp; @@ -624,9 +615,9 @@ /* Remove duplicates. */ - captures_end = captures + size; - tmp = *captures++; - current = captures; + uint16_t *captures_end = captures + size; + uint16_t tmp = *captures++; + uint16_t *current = captures; while (current < captures_end) {
diff --git a/src/pcre2_compile_class.c b/src/pcre2_compile_class.c index f9df259..73a25c0 100644 --- a/src/pcre2_compile_class.c +++ b/src/pcre2_compile_class.c
@@ -524,14 +524,9 @@ compile_block *cb) { class_ranges *cranges; - uint32_t *ptr; - uint32_t *buffer; - uint32_t *dst; uint32_t class_options = 0; size_t range_list_size = 0, total_size, i; uint32_t tmp1, tmp2; - const uint32_t *char_list_next; - uint16_t *next_char; uint32_t char_list_start, char_list_end; uint32_t range_start, range_end; @@ -589,7 +584,7 @@ if (range_list_size == 0) return cranges; - buffer = (uint32_t *)(cranges + 1); + uint32_t *buffer = (uint32_t *)(cranges + 1); parse_class(start_ptr, class_options, buffer); /* Using <= instead of == to help static analysis. */ @@ -624,8 +619,8 @@ } /* Merge ranges whenever possible. */ - dst = buffer; - ptr = buffer + 2; + uint32_t *dst = buffer; + uint32_t *ptr = buffer + 2; range_list_size -= 2; /* The second condition is a very rare corner case, where the end of the last @@ -664,7 +659,7 @@ /* Compute character lists structures. */ - char_list_next = char_list_starts; + const uint32_t *char_list_next = char_list_starts; char_list_start = *char_list_next++; #if PCRE2_CODE_UNIT_WIDTH == 32 char_list_end = XCL_CHAR_LIST_HIGH_32_END; @@ -673,7 +668,7 @@ #else char_list_end = XCL_CHAR_LIST_HIGH_16_END; #endif - next_char = (uint16_t *)(buffer + total_size); + uint16_t *next_char = (uint16_t *)(buffer + total_size); tmp1 = 0; tmp2 = ((sizeof(char_list_starts) / sizeof(uint32_t)) - 1) * XCL_TYPE_BIT_LEN; @@ -1121,7 +1116,6 @@ { uint32_t *pptr = start_ptr; PCRE2_UCHAR *code = *pcode; - BOOL should_flip_negation; const uint8_t *cbits = cb->cbits; /* Some functions such as add_to_class() or eclass processing expects that the bitset is stored in cb->classbits.classbits. */ @@ -1136,9 +1130,6 @@ /* Helper variables for OP_XCLASS opcode (for characters > 255). */ #ifdef SUPPORT_WIDE_CHARS - uint32_t xclass_props; - PCRE2_UCHAR *class_uchardata; - class_ranges *cranges; #else (void)has_bitmap; // Avoid compiler warning. (void)errorcodeptr; // Avoid compiler warning. @@ -1151,16 +1142,15 @@ matching or non-matching code for wide characters. */ - should_flip_negation = FALSE; + BOOL should_flip_negation = FALSE; /* XClass will be used when characters > 255 might match. */ #ifdef SUPPORT_WIDE_CHARS - xclass_props = 0; + uint32_t xclass_props = 0; + class_ranges *cranges = NULL; #if PCRE2_CODE_UNIT_WIDTH == 8 - cranges = NULL; - if (utf) #endif { @@ -1200,7 +1190,7 @@ } } - class_uchardata = code + LINK_SIZE + 2; // For XCLASS items + PCRE2_UCHAR *class_uchardata = code + LINK_SIZE + 2; // For XCLASS items #endif /* SUPPORT_WIDE_CHARS */ /* Initialize the 256-bit (32-byte) bit map to all zeros. We build the map @@ -1563,13 +1553,11 @@ if (*pptr == META_RANGE_LITERAL || *pptr == META_RANGE_ESCAPED) { - uint32_t d; - #ifdef EBCDIC BOOL range_is_literal = (*pptr == META_RANGE_LITERAL); #endif ++pptr; - d = *(pptr++); + uint32_t d = *(pptr++); if (d == META_BIGVALUE) d = *(pptr++); @@ -1850,8 +1838,6 @@ } else { - uint8_t *data; - PCRE2_ASSERT(cranges->char_lists_types <= XCL_TYPE_MASK); #if PCRE2_CODE_UNIT_WIDTH == 8 /* Encode as high / low bytes. */ @@ -1871,7 +1857,7 @@ PCRE2_ASSERT(char_lists_size <= PCRE2_SIZE_MAX - cb->char_lists_size); cb->char_lists_size += char_lists_size; - data = (uint8_t *)cb->start_code - cb->char_lists_size; + uint8_t *data = (uint8_t *)cb->start_code - cb->char_lists_size; memcpy(data, (uint8_t *)(cranges + 1) + cranges->char_lists_start, char_lists_size); @@ -2642,7 +2628,6 @@ eclass_op_info op_info; PCRE2_SIZE previous_length = (lengthptr != NULL) ? *lengthptr : 0; PCRE2_UCHAR *code = *pcode; - PCRE2_UCHAR *previous; BOOL allbitsone = TRUE; context.needs_bitmap = FALSE; @@ -2651,7 +2636,7 @@ context.errorcodeptr = errorcodeptr; context.cb = cb; - previous = code; + PCRE2_UCHAR *previous = code; *code++ = OP_ECLASS; code += LINK_SIZE; *code++ = 0; // Flags, currently zero. @@ -2734,10 +2719,9 @@ PCRE2_DEBUG_UNREACHABLE(); #else BOOL need_map = context.needs_bitmap; - PCRE2_SIZE required_len; PCRE2_ASSERT(op_info.op_single_type == ECL_XCLASS); - required_len = op_info.length + (need_map ? 32 / sizeof(PCRE2_UCHAR) : 0); + PCRE2_SIZE required_len = op_info.length + (need_map ? 32 / sizeof(PCRE2_UCHAR) : 0); if (lengthptr != NULL) { @@ -2758,17 +2742,13 @@ } else { - PCRE2_UCHAR *rest; - PCRE2_SIZE rest_len; - PCRE2_UCHAR flags; - /* 1 unit: OP_XCLASS | LINK_SIZE units | 1 unit: flags | ...rest */ PCRE2_ASSERT(op_info.length >= 1 + LINK_SIZE + 1); - rest = op_info.code_start + 1 + LINK_SIZE + 1; - rest_len = (op_info.code_start + op_info.length) - rest; + PCRE2_UCHAR *rest = op_info.code_start + 1 + LINK_SIZE + 1; + PCRE2_SIZE rest_len = (op_info.code_start + op_info.length) - rest; /* First read any data we use, before memmove splats it. */ - flags = op_info.code_start[1 + LINK_SIZE]; + PCRE2_UCHAR flags = op_info.code_start[1 + LINK_SIZE]; PCRE2_ASSERT((flags & XCL_MAP) == 0); /* Next do the memmove before any writes. */
diff --git a/src/pcre2_dfa_match.c b/src/pcre2_dfa_match.c index 807eddc..707e3f4 100644 --- a/src/pcre2_dfa_match.c +++ b/src/pcre2_dfa_match.c
@@ -432,10 +432,9 @@ { RWS_anchor *rws = *rwsptr; RWS_anchor *new; - uint32_t requested; PCRE2_ASSERT(ovecsize <= UINT32_MAX - RWS_RSIZE - RWS_ANCHOR_SIZE); - requested = RWS_RSIZE + ovecsize + RWS_ANCHOR_SIZE; + uint32_t requested = RWS_RSIZE + ovecsize + RWS_ANCHOR_SIZE; if (rws->next != NULL) { @@ -574,7 +573,6 @@ stateblock *active_states, *new_states, *temp_states; stateblock *next_active_state, *next_new_state; const uint8_t *ctypes, *lcc, *fcc; - PCRE2_SPTR ptr; PCRE2_SPTR end_code; dfa_recursion_info new_recursive; int active_count, new_count, match_count; @@ -732,7 +730,7 @@ /* Loop for scanning the subject */ - ptr = current_subject; + PCRE2_SPTR ptr = current_subject; for (;;) { int i, j; @@ -790,8 +788,6 @@ { stateblock *current_state = active_states + i; BOOL caseless = FALSE; - PCRE2_SPTR code; - uint32_t codevalue; int state_offset = current_state->offset; int rrc; int count; @@ -829,8 +825,8 @@ /* The state offset is the offset to the opcode */ - code = start_code + state_offset; - codevalue = *code; + PCRE2_SPTR code = start_code + state_offset; + uint32_t codevalue = *code; /* If this opcode inspects a character, but we are at the end of the subject, remember the fact for use when testing for a partial match. */ @@ -2322,7 +2318,6 @@ count = current_state->count; // Number already matched if (clen > 0) { - PCRE2_SPTR nptr; int ncount = 0; if (codevalue == OP_EXTUNI_EXTRA + OP_TYPEPOSUPTO) { @@ -2330,7 +2325,7 @@ next_active_state--; } - nptr = PRIV(extuni)(c, ptr + clen, mb->start_subject, end_subject, utf, &ncount); + PCRE2_SPTR nptr = PRIV(extuni)(c, ptr + clen, mb->start_subject, end_subject, utf, &ncount); if (nptr >= end_subject && (mb->moptions & PCRE2_PARTIAL_HARD) != 0) reset_could_continue = TRUE; if (++count >= (int)GET2(code, 1)) @@ -2955,7 +2950,6 @@ #endif { BOOL isinclass = FALSE; - int next_state_offset; PCRE2_SPTR ecode; #ifdef SUPPORT_WIDE_CHARS @@ -3002,7 +2996,7 @@ points to the byte after the end of the class. If there is a quantifier, this is where it will be. */ - next_state_offset = (int)(ecode - start_code); + int next_state_offset = (int)(ecode - start_code); switch (*ecode) { @@ -3121,8 +3115,6 @@ case OP_ASSERTBACK_NOT: { int rc; - int *local_workspace; - PCRE2_SIZE *local_offsets; PCRE2_SPTR endasscode = code + GET(code, 1); RWS_anchor *rws = (RWS_anchor *)RWS; @@ -3134,8 +3126,8 @@ RWS = (int *)rws; } - local_offsets = (PCRE2_SIZE *)(RWS + rws->size - rws->free); - local_workspace = ((int *)local_offsets) + RWS_OVEC_OSIZE; + PCRE2_SIZE *local_offsets = (PCRE2_SIZE *)(RWS + rws->size - rws->free); + int *local_workspace = ((int *)local_offsets) + RWS_OVEC_OSIZE; PCRE2_ASSERT(rws->free >= RWS_RSIZE + RWS_OVEC_OSIZE); rws->free -= RWS_RSIZE + RWS_OVEC_OSIZE; @@ -3170,7 +3162,6 @@ case OP_SCOND: { int codelink = (int)GET(code, 1); - PCRE2_UCHAR condcode; /* Because of the way auto-callout works during compile, a callout item is inserted between OP_COND and an assertion condition. This does not @@ -3188,7 +3179,7 @@ code += callout_length; // Skip callout data } - condcode = code[LINK_SIZE + 1]; + PCRE2_UCHAR condcode = code[LINK_SIZE + 1]; /* Back reference conditions and duplicate named recursion conditions are not supported */ @@ -3235,8 +3226,6 @@ else { int rc; - int *local_workspace; - PCRE2_SIZE *local_offsets; PCRE2_SPTR asscode = code + LINK_SIZE + 1; PCRE2_SPTR endasscode = asscode + GET(asscode, 1); RWS_anchor *rws = (RWS_anchor *)RWS; @@ -3249,8 +3238,8 @@ RWS = (int *)rws; } - local_offsets = (PCRE2_SIZE *)(RWS + rws->size - rws->free); - local_workspace = ((int *)local_offsets) + RWS_OVEC_OSIZE; + PCRE2_SIZE *local_offsets = (PCRE2_SIZE *)(RWS + rws->size - rws->free); + int *local_workspace = ((int *)local_offsets) + RWS_OVEC_OSIZE; PCRE2_ASSERT(rws->free >= RWS_RSIZE + RWS_OVEC_OSIZE); rws->free -= RWS_RSIZE + RWS_OVEC_OSIZE; @@ -3289,8 +3278,6 @@ case OP_RECURSE: { int rc; - int *local_workspace; - PCRE2_SIZE *local_offsets; RWS_anchor *rws = (RWS_anchor *)RWS; PCRE2_SPTR callpat = start_code + GET(code, 1); uint32_t recno = (callpat == mb->start_code) ? 0 : GET2(callpat, 1 + LINK_SIZE); @@ -3307,8 +3294,8 @@ RWS = (int *)rws; } - local_offsets = (PCRE2_SIZE *)(RWS + rws->size - rws->free); - local_workspace = ((int *)local_offsets) + RWS_OVEC_RSIZE; + PCRE2_SIZE *local_offsets = (PCRE2_SIZE *)(RWS + rws->size - rws->free); + int *local_workspace = ((int *)local_offsets) + RWS_OVEC_RSIZE; PCRE2_ASSERT(rws->free >= RWS_RSIZE + RWS_OVEC_RSIZE); rws->free -= RWS_RSIZE + RWS_OVEC_RSIZE; @@ -3394,8 +3381,6 @@ case OP_BRAPOSZERO: { int rc; - int *local_workspace; - PCRE2_SIZE *local_offsets; PCRE2_SIZE charcount, matched_count; PCRE2_SPTR local_ptr = ptr; RWS_anchor *rws = (RWS_anchor *)RWS; @@ -3409,8 +3394,8 @@ RWS = (int *)rws; } - local_offsets = (PCRE2_SIZE *)(RWS + rws->size - rws->free); - local_workspace = ((int *)local_offsets) + RWS_OVEC_OSIZE; + PCRE2_SIZE *local_offsets = (PCRE2_SIZE *)(RWS + rws->size - rws->free); + int *local_workspace = ((int *)local_offsets) + RWS_OVEC_OSIZE; PCRE2_ASSERT(rws->free >= RWS_RSIZE + RWS_OVEC_OSIZE); rws->free -= RWS_RSIZE + RWS_OVEC_OSIZE; @@ -3466,14 +3451,13 @@ if (matched_count > 0 || allow_zero) { PCRE2_SPTR end_subpattern = code; - int next_state_offset; do { end_subpattern += GET(end_subpattern, 1); } while (*end_subpattern == OP_ALT); - next_state_offset = (int)(end_subpattern - start_code + LINK_SIZE + 1); + int next_state_offset = (int)(end_subpattern - start_code + LINK_SIZE + 1); /* Optimization: if there are no more active states, and there are no new states yet set up, then skip over the subject string @@ -3512,8 +3496,6 @@ case OP_ONCE: { int rc; - int *local_workspace; - PCRE2_SIZE *local_offsets; RWS_anchor *rws = (RWS_anchor *)RWS; if (rws->free < RWS_RSIZE + RWS_OVEC_OSIZE) @@ -3524,8 +3506,8 @@ RWS = (int *)rws; } - local_offsets = (PCRE2_SIZE *)(RWS + rws->size - rws->free); - local_workspace = ((int *)local_offsets) + RWS_OVEC_OSIZE; + PCRE2_SIZE *local_offsets = (PCRE2_SIZE *)(RWS + rws->size - rws->free); + int *local_workspace = ((int *)local_offsets) + RWS_OVEC_OSIZE; PCRE2_ASSERT(rws->free >= RWS_RSIZE + RWS_OVEC_OSIZE); rws->free -= RWS_RSIZE + RWS_OVEC_OSIZE; @@ -3734,10 +3716,6 @@ PCRE2_UCHAR null_str[1] = { 0xcd }; PCRE2_SPTR original_subject = subject; - PCRE2_SPTR start_match; - PCRE2_SPTR end_subject; - PCRE2_SPTR bumpalong_limit; - PCRE2_SPTR req_cu_ptr; BOOL utf, anchored, startline, firstline; BOOL has_first_cu = FALSE; @@ -3886,9 +3864,9 @@ /* Set some local values */ utf = (re->overall_options & PCRE2_UTF) != 0; - start_match = subject + start_offset; - end_subject = subject + length; - req_cu_ptr = start_match - 1; + PCRE2_SPTR start_match = subject + start_offset; + PCRE2_SPTR end_subject = subject + length; + PCRE2_SPTR req_cu_ptr = start_match - 1; anchored = (options & (PCRE2_ANCHORED | PCRE2_DFA_RESTART)) != 0 || (re->overall_options & PCRE2_ANCHORED) != 0; @@ -3897,7 +3875,7 @@ startline = (re->flags & PCRE2_STARTLINE) != 0; firstline = !anchored && (re->overall_options & PCRE2_FIRSTLINE) != 0; - bumpalong_limit = end_subject; + PCRE2_SPTR bumpalong_limit = end_subject; /* Initialize and set up the fixed fields in the callout block, with a pointer in the match block. */ @@ -4362,8 +4340,6 @@ if ((mb->moptions & (PCRE2_PARTIAL_HARD | PCRE2_PARTIAL_SOFT)) == 0) { - PCRE2_SPTR p; - /* The minimum matching length is a lower bound; no actual string of that length may actually match the pattern. Although the value is, strictly, in characters, we treat it as code units to avoid spending too much time @@ -4394,7 +4370,7 @@ sufficiently long, but it's worth searching a lot more for unanchored patterns. */ - p = start_match + (has_first_cu ? 1 : 0); + PCRE2_SPTR p = start_match + (has_first_cu ? 1 : 0); if (has_req_cu && p > req_cu_ptr) { PCRE2_SIZE check_length = end_subject - start_match;
diff --git a/src/pcre2_jit_char_inc.h b/src/pcre2_jit_char_inc.h index c8dd49b..fdf2a1f 100644 --- a/src/pcre2_jit_char_inc.h +++ b/src/pcre2_jit_char_inc.h
@@ -94,10 +94,7 @@ size_t range_count = 0, est_range_count; size_t est_stack_size, tmp; uint32_t type, list_ind; - uint32_t est_type; uint32_t char_list_add, range_start, range_end; - const uint8_t *next_char; - const uint8_t *est_next_char; #if defined SUPPORT_UNICODE && (PCRE2_CODE_UNIT_WIDTH == 8 || PCRE2_CODE_UNIT_WIDTH == 16) BOOL utf = common->utf; #endif /* SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == [8|16] */ @@ -136,12 +133,12 @@ #endif /* CODE_UNIT_WIDTH */ /* Align characters. */ - next_char = (const uint8_t *)common->start - (GET(cc, 0) << 1); + const uint8_t *next_char = (const uint8_t *)common->start - (GET(cc, 0) << 1); type &= XCL_TYPE_MASK; /* Estimate size. */ - est_next_char = next_char; - est_type = type; + const uint8_t *est_next_char = next_char; + uint32_t est_type = type; est_range_count = 0; list_ind = 0; @@ -325,11 +322,10 @@ xclass_update_min_max(compiler_common *common, PCRE2_SPTR cc, sljit_u32 *min_ptr, sljit_u32 *max_ptr) { - uint32_t type, list_ind, c; + uint32_t type, c; sljit_u32 min = *min_ptr; sljit_u32 max = *max_ptr; uint32_t char_list_add; - const uint8_t *next_char; BOOL utf = TRUE; /* This function is pointless without utf 8/16. */ @@ -371,7 +367,7 @@ #endif /* CODE_UNIT_WIDTH */ /* Align characters. */ - next_char = (const uint8_t *)common->start - (GET(cc, 0) << 1); + const uint8_t *next_char = (const uint8_t *)common->start - (GET(cc, 0) << 1); type &= XCL_TYPE_MASK; SLJIT_ASSERT(type != 0); @@ -379,7 +375,7 @@ /* Detect minimum. */ /* Skip unused ranges. */ - list_ind = 0; + uint32_t list_ind = 0; while ((type & (XCL_BEGIN_WITH_RANGE | XCL_ITEM_COUNT_MASK)) == 0) { type >>= XCL_TYPE_BIT_LEN; @@ -535,8 +531,6 @@ sljit_uw c, charoffset; sljit_u32 max = READ_CHAR_MAX, min = 0; struct sljit_jump *jump = NULL; - PCRE2_UCHAR flags; - PCRE2_SPTR ccbegin; sljit_u32 compares, invertcmp, depth; sljit_u32 first_item, last_item, mid_item; sljit_u32 range_start, range_end; @@ -553,8 +547,8 @@ SLJIT_ASSERT(common->locals_size >= SSIZE_OF(sw)); /* Scanning the necessary info. */ - flags = *cc++; - ccbegin = cc; + PCRE2_UCHAR flags = *cc++; + PCRE2_SPTR ccbegin = cc; compares = 0; if (flags & XCL_MAP) @@ -1301,7 +1295,6 @@ { DEFINE_COMPILER; PCRE2_SPTR end = cc + GET(cc, 0) - 1; - PCRE2_SPTR begin; jump_list *not_found; jump_list *found = NULL; @@ -1316,7 +1309,7 @@ cc += 32 / sizeof(PCRE2_UCHAR); } - begin = cc; + PCRE2_SPTR begin = cc; OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCAL0, ECLASS_CHAR_DATA, 0); OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), LOCAL1, ECLASS_STACK_DATA, 0); @@ -1398,7 +1391,6 @@ unsigned int othercasebit = 0; PCRE2_SPTR othercasechar = NULL; #ifdef SUPPORT_UNICODE - int utflength; #endif if (caseless && char_has_othercase(common, cc)) @@ -1447,7 +1439,7 @@ } #ifdef SUPPORT_UNICODE - utflength = 1; + int utflength = 1; if (common->utf && HAS_EXTRALEN(*cc)) utflength += GET_EXTRALEN(*cc); @@ -1737,12 +1729,11 @@ PCRE2_SPTR end_subject = args->end; int lgb, rgb, ricount; PCRE2_SPTR bptr; - uint32_t c; BOOL was_ep_ZWJ = FALSE; /* Patch by PH */ /* GETCHARINC(c, cc); */ - c = *cc++; + uint32_t c = *cc++; #if PCRE2_CODE_UNIT_WIDTH == 32 if (c >= 0x110000)
diff --git a/src/pcre2_jit_compile.c b/src/pcre2_jit_compile.c index 28de173..be5ba46 100644 --- a/src/pcre2_jit_compile.c +++ b/src/pcre2_jit_compile.c
@@ -1435,7 +1435,6 @@ int start) { PCRE2_SPTR begin = cc; - PCRE2_SPTR next_alt; PCRE2_SPTR end; PCRE2_SPTR accelerated_start; int result = 0; @@ -1445,7 +1444,7 @@ SLJIT_ASSERT(*cc != OP_CBRA || is_optimized_cbracket(common, GET2(cc, 1 + LINK_SIZE))); SLJIT_ASSERT(start < EARLY_FAIL_ENHANCE_MAX); - next_alt = cc + GET(cc, 1); + PCRE2_SPTR next_alt = cc + GET(cc, 1); if (*next_alt == OP_ALT && start < 1) start = 1; @@ -1856,9 +1855,7 @@ detect_repeat(compiler_common *common, PCRE2_SPTR begin) { PCRE2_SPTR end = bracketend(begin); - PCRE2_SPTR next; PCRE2_SPTR next_end; - PCRE2_SPTR max_end; PCRE2_UCHAR type; sljit_sw length = end - begin; sljit_s32 min, max, i; @@ -1872,7 +1869,7 @@ if (PRIVATE_DATA(end - LINK_SIZE) != 0) return TRUE; - next = end; + PCRE2_SPTR next = end; min = 1; while (1) { @@ -1889,7 +1886,7 @@ return FALSE; max = 0; - max_end = next; + PCRE2_SPTR max_end = next; if (*next == OP_BRAZERO || *next == OP_BRAMINZERO) { type = *next; @@ -2673,17 +2670,14 @@ static BOOL recurse_check_bit(compiler_common *common, sljit_sw bit_index) { - uint8_t *byte; - uint8_t mask; - SLJIT_ASSERT((bit_index & (sizeof(sljit_sw) - 1)) == 0); bit_index >>= SLJIT_WORD_SHIFT; SLJIT_ASSERT((bit_index >> 3) < common->recurse_bitset_size); - mask = 1 << (bit_index & 0x7); - byte = common->recurse_bitset + (bit_index >> 3); + uint8_t mask = 1 << (bit_index & 0x7); + uint8_t *byte = common->recurse_bitset + (bit_index >> 3); if (*byte & mask) return FALSE; @@ -3730,12 +3724,11 @@ allocate_read_only_data(compiler_common *common, sljit_uw size) { DEFINE_COMPILER; - sljit_uw *result; if (SLJIT_UNLIKELY(sljit_get_compiler_error(compiler))) return NULL; - result = (sljit_uw *)SLJIT_MALLOC(size + sizeof(sljit_uw), compiler->allocator_data); + sljit_uw *result = (sljit_uw *)SLJIT_MALLOC(size + sizeof(sljit_uw), compiler->allocator_data); if (SLJIT_UNLIKELY(result == NULL)) { sljit_set_compiler_memory_error(compiler); @@ -3796,7 +3789,6 @@ { DEFINE_COMPILER; sljit_u32 size = (sljit_u32)(common->early_fail_end_ptr - common->early_fail_start_ptr); - sljit_u32 uncleared_size; sljit_s32 src = SLJIT_IMM; sljit_s32 i; struct sljit_label *loop; @@ -3825,7 +3817,7 @@ GET_LOCAL_BASE(TMP1, 0, common->early_fail_start_ptr); - uncleared_size = ((size / sizeof(sljit_sw)) % 3) * sizeof(sljit_sw); + sljit_u32 uncleared_size = ((size / sizeof(sljit_sw)) % 3) * sizeof(sljit_sw); OP2(SLJIT_ADD, TMP2, 0, TMP1, 0, SLJIT_IMM, size - uncleared_size); @@ -4041,7 +4033,6 @@ return_with_partial_match(compiler_common *common, struct sljit_label *quit) { DEFINE_COMPILER; - sljit_s32 mov_opcode; sljit_s32 arguments_reg = !HAS_VIRTUAL_REGISTERS ? ARGUMENTS : SLJIT_R1; SLJIT_COMPILE_ASSERT(STR_END == SLJIT_S0, str_end_must_be_saved_reg0); @@ -4061,7 +4052,7 @@ 0); OP1(SLJIT_MOV, SLJIT_R1, 0, SLJIT_MEM1(arguments_reg), SLJIT_OFFSETOF(jit_arguments, match_data)); - mov_opcode = (sizeof(PCRE2_SIZE) == 4) ? SLJIT_MOV_U32 : SLJIT_MOV; + sljit_s32 mov_opcode = (sizeof(PCRE2_SIZE) == 4) ? SLJIT_MOV_U32 : SLJIT_MOV; OP2(SLJIT_SUB, SLJIT_R2, 0, SLJIT_R2, 0, SLJIT_S1, 0); #if PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 @@ -4148,7 +4139,7 @@ char_get_othercase_bit(compiler_common *common, PCRE2_SPTR cc) { /* Detects if the character and its othercase has only 1 bit difference. */ - unsigned int c, oc, bit; + unsigned int c, oc; #if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH == 8 int n; #endif @@ -4182,7 +4173,7 @@ SLJIT_ASSERT(c != oc); - bit = c ^ oc; + unsigned int bit = c ^ oc; #ifndef EBCDIC /* Optimized for English alphabet. */ @@ -6743,12 +6734,12 @@ static int extract_class_ranges(const sljit_u8 *bits, int *ranges, int max_ranges) { - sljit_u8 bit, cbit, all; + sljit_u8 cbit; int i, byte, length = 0; - bit = bits[0] & 0x1; + sljit_u8 bit = bits[0] & 0x1; /* All bits will be zero or one (since bit is zero or one). */ - all = (sljit_u8)-bit; + sljit_u8 all = (sljit_u8)-bit; for (i = 0; i < 256;) { @@ -6991,13 +6982,11 @@ struct sljit_label *start; struct sljit_jump *match; fast_forward_char_data chars[MAX_N_CHARS]; - sljit_s32 offset; PCRE2_UCHAR mask; PCRE2_UCHAR *char_set, *char_set_end; int i, max, from; int range_right = -1, range_len; sljit_u8 *update_table = NULL; - BOOL in_range; for (i = 0; i < MAX_N_CHARS; i++) { @@ -7050,7 +7039,7 @@ return TRUE; #endif - in_range = FALSE; + BOOL in_range = FALSE; /* Prevent compiler "uninitialized" warning */ from = 0; range_len = 4 /* minimum length */ - 1; @@ -7099,7 +7088,7 @@ } } - offset = -1; + sljit_s32 offset = -1; /* Scan forward. */ for (i = 0; i < max; i++) { @@ -7236,9 +7225,8 @@ fast_forward_first_char(compiler_common *common) { PCRE2_UCHAR first_char = (PCRE2_UCHAR)(common->re->first_codeunit); - PCRE2_UCHAR oc; - oc = first_char; + PCRE2_UCHAR oc = first_char; if ((common->re->flags & PCRE2_FIRSTCASELESS) != 0) { oc = TABLE_GET(first_char, common->fcc, first_char); @@ -7828,7 +7816,6 @@ /* May destroy TMP1. */ DEFINE_COMPILER; int ranges[MAX_CLASS_RANGE_SIZE]; - sljit_u8 bit; int i, length; length = extract_class_ranges(bits, ranges, MAX_CLASS_RANGE_SIZE); @@ -7836,7 +7823,7 @@ return FALSE; /* Membership of the highest code unit in the bitmap. */ - bit = (bits[31] >> 7) & 0x1; + sljit_u8 bit = (bits[31] >> 7) & 0x1; if (((bit == 0) && nclass) || ((bit == 1) && !nclass)) { @@ -7991,7 +7978,6 @@ DEFINE_COMPILER; uint16_t char_list[MAX_CLASS_CHARS_SIZE]; uint8_t byte; - sljit_s32 type; int i, j, k, len, c; if (!sljit_has_cpu_feature(SLJIT_HAS_CMOV)) @@ -8091,7 +8077,7 @@ if (invert) nclass = !nclass; - type = nclass ? SLJIT_NOT_EQUAL : SLJIT_EQUAL; + sljit_s32 type = nclass ? SLJIT_NOT_EQUAL : SLJIT_EQUAL; add_jump(compiler, backtracks, CMP(type, TMP2, 0, SLJIT_IMM, 0)); return TRUE; } @@ -8759,7 +8745,6 @@ DEFINE_COMPILER; int count = GET2(cc, 1 + IMM2_SIZE); PCRE2_SPTR slot = common->name_table + GET2(cc, 1) * common->name_entry_size; - unsigned int offset; jump_list *found = NULL; SLJIT_ASSERT(*cc == OP_DNREF || *cc == OP_DNREFI); @@ -8769,14 +8754,14 @@ count--; while (count-- > 0) { - offset = GET2(slot, 0) << 1; + unsigned int offset = GET2(slot, 0) << 1; GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset)); add_jump(compiler, &found, CMP(SLJIT_NOT_EQUAL, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset), TMP1, 0)); slot += common->name_entry_size; } - offset = GET2(slot, 0) << 1; + unsigned int offset = GET2(slot, 0) << 1; GET_LOCAL_BASE(TMP2, 0, OVECTOR(offset)); if (backtracks != NULL && !common->unset_backref) add_jump(compiler, backtracks, @@ -9005,7 +8990,6 @@ DEFINE_COMPILER; BOOL ref = (*cc == OP_REF || *cc == OP_REFI); backtrack_common *backtrack; - PCRE2_UCHAR type; int local_start = LOCAL2; int offset = 0; struct sljit_label *label; @@ -9032,7 +9016,7 @@ #endif } - type = cc[1 + IMM2_SIZE]; + PCRE2_UCHAR type = cc[1 + IMM2_SIZE]; SLJIT_COMPILE_ASSERT((OP_CRSTAR & 0x1) == 0, crstar_opcode_must_be_even); /* Update ref_update_local_size() when this changes. */ @@ -9349,13 +9333,11 @@ backtrack_common *backtrack; recurse_entry *entry = common->entries; recurse_entry *prev = NULL; - PCRE2_SPTR end; sljit_sw start = GET(cc, 1); - sljit_uw arg_size; PCRE2_SPTR start_cc; BOOL needs_control_head; - end = cc + 1 + LINK_SIZE; + PCRE2_SPTR end = cc + 1 + LINK_SIZE; while (*end == OP_CREF) end += 1 + IMM2_SIZE; @@ -9373,7 +9355,7 @@ } cc += 1 + LINK_SIZE; - arg_size = (sljit_uw)IN_UCHARS(end - cc); + sljit_uw arg_size = (sljit_uw)IN_UCHARS(end - cc); while (entry != NULL) { if (entry->start == start && entry->arg_size == arg_size && @@ -9419,9 +9401,7 @@ do_callout_jit(struct jit_arguments *arguments, pcre2_callout_block *callout_block, PCRE2_SPTR *jit_ovector) { - PCRE2_SPTR begin; - PCRE2_SIZE *ovector; - sljit_u32 oveccount, capture_top; + sljit_u32 capture_top; if (arguments->callout == NULL) return 0; @@ -9429,9 +9409,9 @@ SLJIT_COMPILE_ASSERT(sizeof(PCRE2_SIZE) <= sizeof(sljit_sw), pcre2_size_must_be_lower_than_sljit_sw_size); - begin = arguments->begin; - ovector = (PCRE2_SIZE *)(callout_block + 1); - oveccount = callout_block->capture_top; + PCRE2_SPTR begin = arguments->begin; + PCRE2_SIZE *ovector = (PCRE2_SIZE *)(callout_block + 1); + sljit_u32 oveccount = callout_block->capture_top; SLJIT_ASSERT(oveccount >= 1); @@ -9479,10 +9459,8 @@ { DEFINE_COMPILER; backtrack_common *backtrack; - sljit_s32 mov_opcode; unsigned int callout_length = (*cc == OP_CALLOUT) ? PRIV(OP_lengths)[OP_CALLOUT] : GET(cc, 1 + 2 * LINK_SIZE); - sljit_sw value1; sljit_sw value2; sljit_sw value3; sljit_s32 callout_arg_size = @@ -9498,7 +9476,7 @@ SLJIT_ASSERT(common->capture_last_ptr != 0); OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), common->capture_last_ptr); OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0); - value1 = (*cc == OP_CALLOUT) ? cc[1 + 2 * LINK_SIZE] : 0; + sljit_sw value1 = (*cc == OP_CALLOUT) ? cc[1 + 2 * LINK_SIZE] : 0; OP1(SLJIT_MOV_U32, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(callout_number), SLJIT_IMM, value1); OP1(SLJIT_MOV_U32, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(capture_last), TMP2, 0); OP1(SLJIT_MOV_U32, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(capture_top), SLJIT_IMM, @@ -9509,7 +9487,7 @@ if (common->mark_ptr != 0) OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, mark_ptr)); - mov_opcode = (sizeof(PCRE2_SIZE) == 4) ? SLJIT_MOV_U32 : SLJIT_MOV; + sljit_s32 mov_opcode = (sizeof(PCRE2_SIZE) == 4) ? SLJIT_MOV_U32 : SLJIT_MOV; OP1(mov_opcode, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(pattern_position), SLJIT_IMM, GET(cc, 1)); OP1(mov_opcode, SLJIT_MEM1(STACK_TOP), CALLOUT_ARG_OFFSET(next_item_length), SLJIT_IMM, @@ -9703,20 +9681,15 @@ BOOL conditional) { DEFINE_COMPILER; - int framesize; int extrasize; BOOL local_quit_available = FALSE; BOOL needs_control_head; BOOL end_block_size = 0; BOOL has_vreverse; - int private_data_ptr; backtrack_common altbacktrack; - PCRE2_SPTR ccbegin; - PCRE2_UCHAR opcode; PCRE2_UCHAR bra = OP_BRA; jump_list *tmp = NULL; jump_list **target = (conditional) ? &backtrack->condfailed : &backtrack->common.own_backtracks; - jump_list **found; /* Saving previous accept variables. */ BOOL save_local_quit_available = common->local_quit_available; BOOL save_in_positive_assertion = common->in_positive_assertion; @@ -9740,15 +9713,15 @@ cc++; } - private_data_ptr = PRIVATE_DATA(cc); + int private_data_ptr = PRIVATE_DATA(cc); SLJIT_ASSERT(private_data_ptr != 0); - framesize = get_framesize(common, cc, NULL, FALSE, &needs_control_head); + int framesize = get_framesize(common, cc, NULL, FALSE, &needs_control_head); backtrack->framesize = framesize; backtrack->private_data_ptr = private_data_ptr; - opcode = *cc; + PCRE2_UCHAR opcode = *cc; SLJIT_ASSERT(opcode >= OP_ASSERT && opcode <= OP_ASSERTBACK_NOT); - found = (opcode == OP_ASSERT || opcode == OP_ASSERTBACK) ? &tmp : target; - ccbegin = cc; + jump_list **found = (opcode == OP_ASSERT || opcode == OP_ASSERTBACK) ? &tmp : target; + PCRE2_SPTR ccbegin = cc; cc += GET(cc, 1); if (bra == OP_BRAMINZERO) @@ -10402,19 +10375,14 @@ { DEFINE_COMPILER; backtrack_common *backtrack; - PCRE2_UCHAR opcode; int private_data_ptr = 0; int offset = 0; int i, stacksize; int repeat_ptr = 0, repeat_length = 0; int repeat_type = 0, repeat_count = 0; - PCRE2_SPTR ccbegin; - PCRE2_SPTR matchingpath; PCRE2_SPTR slot; PCRE2_UCHAR bra = OP_BRA; - PCRE2_UCHAR ket; assert_backtrack *assert; - BOOL has_alternatives; BOOL needs_control_head = FALSE; BOOL has_vreverse = FALSE; struct sljit_jump *jump; @@ -10429,13 +10397,12 @@ { bra = *cc; cc++; - opcode = *cc; } - opcode = *cc; - ccbegin = cc; - matchingpath = bracketend(cc) - 1 - LINK_SIZE; - ket = *matchingpath; + PCRE2_UCHAR opcode = *cc; + PCRE2_SPTR ccbegin = cc; + PCRE2_SPTR matchingpath = bracketend(cc) - 1 - LINK_SIZE; + PCRE2_UCHAR ket = *matchingpath; if (ket == OP_KET && PRIVATE_DATA(matchingpath) != 0) { repeat_ptr = PRIVATE_DATA(matchingpath); @@ -10455,7 +10422,7 @@ !((bra == OP_BRAZERO && ket == OP_KETRMIN) || (bra == OP_BRAMINZERO && ket == OP_KETRMAX))); cc += GET(cc, 1); - has_alternatives = *cc == OP_ALT; + BOOL has_alternatives = *cc == OP_ALT; if (SLJIT_UNLIKELY(opcode == OP_COND || opcode == OP_SCOND)) { SLJIT_COMPILE_ASSERT(OP_DNRREF == OP_RREF + 1 && OP_FALSE == OP_RREF + 2 && @@ -11133,14 +11100,13 @@ if (opcode == OP_ONCE) { - int data; int framesize = BACKTRACK_AS(bracket_backtrack)->u.framesize; SLJIT_ASSERT(SHRT_MIN <= framesize && framesize < SHRT_MAX / 2); /* We temporarily encode the needs_control_head in the lowest bit. The real value should be short enough for this operation to work without triggering Undefined Behaviour. */ - data = (int)((short)((unsigned short)framesize << 1) | (needs_control_head ? 1 : 0)); + int data = (int)((short)((unsigned short)framesize << 1) | (needs_control_head ? 1 : 0)); BACKTRACK_AS(bracket_backtrack)->u.framesize = data; } @@ -11152,11 +11118,8 @@ { DEFINE_COMPILER; backtrack_common *backtrack; - PCRE2_UCHAR opcode; - int private_data_ptr; int cbraprivptr = 0; BOOL needs_control_head; - int framesize; int stacksize; int offset = 0; BOOL zero = FALSE; @@ -11172,8 +11135,8 @@ cc++; } - opcode = *cc; - private_data_ptr = PRIVATE_DATA(cc); + PCRE2_UCHAR opcode = *cc; + int private_data_ptr = PRIVATE_DATA(cc); SLJIT_ASSERT(private_data_ptr != 0); BACKTRACK_AS(bracketpos_backtrack)->private_data_ptr = private_data_ptr; switch (opcode) @@ -11199,7 +11162,7 @@ break; } - framesize = get_framesize(common, cc, NULL, FALSE, &needs_control_head); + int framesize = get_framesize(common, cc, NULL, FALSE, &needs_control_head); BACKTRACK_AS(bracketpos_backtrack)->framesize = framesize; if (framesize < 0) { @@ -11603,7 +11566,6 @@ PCRE2_UCHAR type; sljit_u32 max = 0, exact; sljit_s32 early_fail_ptr = PRIVATE_DATA(cc + 1); - sljit_s32 early_fail_type; BOOL charpos_enabled, use_tmp; PCRE2_UCHAR charpos_char; unsigned int charpos_othercasebit; @@ -11618,7 +11580,7 @@ int offset1 = (private_data_ptr == 0) ? STACK(1) : private_data_ptr + SSIZE_OF(sw); int tmp_base, tmp_offset; - early_fail_type = (early_fail_ptr & 0x7); + sljit_s32 early_fail_type = (early_fail_ptr & 0x7); early_fail_ptr >>= 3; /* During recursion, these optimizations are disabled. */ @@ -12492,7 +12454,6 @@ DEFINE_COMPILER; backtrack_common *backtrack; BOOL needs_control_head; - int size; PUSH_BACKTRACK_NOVALUE(sizeof(then_trap_backtrack), cc); common->then_trap = BACKTRACK_AS(then_trap_backtrack); @@ -12501,7 +12462,7 @@ BACKTRACK_AS(then_trap_backtrack)->framesize = get_framesize(common, cc, ccend, FALSE, &needs_control_head); - size = BACKTRACK_AS(then_trap_backtrack)->framesize; + int size = BACKTRACK_AS(then_trap_backtrack)->framesize; size = 3 + (size < 0 ? 0 : size); OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(SLJIT_SP), common->control_head_ptr); @@ -13125,9 +13086,8 @@ DEFINE_COMPILER; PCRE2_SPTR cc = current->cc; BOOL ref = (*cc == OP_REF || *cc == OP_REFI); - PCRE2_UCHAR type; - type = cc[PRIV(OP_lengths)[*cc]]; + PCRE2_UCHAR type = cc[PRIV(OP_lengths)[*cc]]; if (CURRENT_AS(ref_iterator_backtrack)->possessive_or_exact) { @@ -13261,12 +13221,9 @@ int private_data_ptr = CURRENT_AS(bracket_backtrack)->private_data_ptr; int repeat_ptr = 0, repeat_type = 0, repeat_count = 0; PCRE2_SPTR cc = current->cc; - PCRE2_SPTR ccbegin; PCRE2_SPTR ccprev; PCRE2_UCHAR bra = OP_BRA; - PCRE2_UCHAR ket; const assert_backtrack *assert; - BOOL has_alternatives; BOOL needs_control_head = FALSE; BOOL has_vreverse; struct sljit_jump *brazero = NULL; @@ -13284,8 +13241,8 @@ } opcode = *cc; - ccbegin = bracketend(cc) - 1 - LINK_SIZE; - ket = *ccbegin; + PCRE2_SPTR ccbegin = bracketend(cc) - 1 - LINK_SIZE; + PCRE2_UCHAR ket = *ccbegin; if (ket == OP_KET && PRIVATE_DATA(ccbegin) != 0) { repeat_ptr = PRIVATE_DATA(ccbegin); @@ -13300,7 +13257,7 @@ ccbegin = cc; cc += GET(cc, 1); - has_alternatives = *cc == OP_ALT; + BOOL has_alternatives = *cc == OP_ALT; if (SLJIT_UNLIKELY(opcode == OP_COND) || SLJIT_UNLIKELY(opcode == OP_SCOND)) has_alternatives = (ccbegin[1 + LINK_SIZE] >= OP_ASSERT && ccbegin[1 + LINK_SIZE] <= OP_ASSERTBACK_NOT) || @@ -14012,8 +13969,6 @@ { DEFINE_COMPILER; struct sljit_jump *jump; - int framesize; - int size; if (CURRENT_AS(then_trap_backtrack)->then_trap) { @@ -14021,7 +13976,7 @@ return; } - size = CURRENT_AS(then_trap_backtrack)->framesize; + int size = CURRENT_AS(then_trap_backtrack)->framesize; size = 3 + (size < 0 ? 0 : size); OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(size - 3)); @@ -14030,7 +13985,7 @@ set_jumps(CURRENT_AS(then_trap_backtrack)->quit, LABEL()); - framesize = CURRENT_AS(then_trap_backtrack)->framesize; + int framesize = CURRENT_AS(then_trap_backtrack)->framesize; SLJIT_ASSERT(framesize != 0); /* STACK_TOP is set by THEN. */ @@ -14489,10 +14444,7 @@ compiler_common *common = &common_data; const sljit_u8 *tables = re->tables; void *allocator_data = &re->memctl; - int private_data_size; - PCRE2_SPTR ccend; executable_functions *functions; - void *executable_func; sljit_uw executable_size, private_data_length, total_length; struct sljit_label *mainloop_label = NULL; struct sljit_label *continue_match_label; @@ -14626,7 +14578,7 @@ else common->invalid_utf = FALSE; #endif /* SUPPORT_UNICODE */ - ccend = bracketend(common->start); + PCRE2_SPTR ccend = bracketend(common->start); /* Calculate the local space size on the stack. */ common->ovector_start = LOCAL0; @@ -14723,7 +14675,7 @@ SLJIT_ASSERT(!(common->req_char_ptr != 0 && common->start_used_ptr != 0)); common->cbra_ptr = OVECTOR_START + (re->top_bracket + 1) * 2 * sizeof(sljit_sw); - private_data_size = common->cbra_ptr + (re->top_bracket + 1) * sizeof(sljit_sw); + int private_data_size = common->cbra_ptr + (re->top_bracket + 1) * sizeof(sljit_sw); if (common->verb_offsets != NULL) { @@ -15239,7 +15191,7 @@ if (common->verb_offsets != NULL) SLJIT_FREE(common->verb_offsets, allocator_data); - executable_func = sljit_generate_code(compiler, 0, NULL); + void *executable_func = sljit_generate_code(compiler, 0, NULL); executable_size = sljit_get_generated_code_size(compiler); sljit_free_compiler(compiler); @@ -15311,7 +15263,6 @@ pcre2_real_code *re = (pcre2_real_code *)code; #ifdef SUPPORT_JIT void *exec_memory; - executable_functions *functions; static int executable_allocator_is_working = -1; if (executable_allocator_is_working == -1) @@ -15383,7 +15334,7 @@ */ #ifdef SUPPORT_JIT - functions = (executable_functions *)re->executable_jit; + executable_functions *functions = (executable_functions *)re->executable_jit; #endif if ((options & PCRE2_JIT_INVALID_UTF) != 0)
diff --git a/src/pcre2_jit_misc_inc.h b/src/pcre2_jit_misc_inc.h index 6687035..7cf5ba7 100644 --- a/src/pcre2_jit_misc_inc.h +++ b/src/pcre2_jit_misc_inc.h
@@ -134,7 +134,6 @@ #else /* SUPPORT_JIT */ - pcre2_jit_stack *jit_stack; if (startsize == 0 || maxsize == 0 || maxsize > SIZE_MAX - STACK_GROWTH_RATE) return NULL; @@ -143,7 +142,8 @@ startsize = (startsize + STACK_GROWTH_RATE - 1) & (size_t)(~(STACK_GROWTH_RATE - 1)); maxsize = (maxsize + STACK_GROWTH_RATE - 1) & (size_t)(~(STACK_GROWTH_RATE - 1)); - jit_stack = PRIV(memctl_malloc)(sizeof(pcre2_real_jit_stack), (pcre2_memctl *)gcontext); + pcre2_jit_stack *jit_stack = + PRIV(memctl_malloc)(sizeof(pcre2_real_jit_stack), (pcre2_memctl *)gcontext); if (jit_stack == NULL) return NULL; jit_stack->stack = sljit_allocate_stack(startsize, maxsize, &jit_stack->memctl);
diff --git a/src/pcre2_jit_simd_inc.h b/src/pcre2_jit_simd_inc.h index e4cb40f..8a25120 100644 --- a/src/pcre2_jit_simd_inc.h +++ b/src/pcre2_jit_simd_inc.h
@@ -335,7 +335,6 @@ /* The AVX2 code path is currently disabled. */ /* sljit_s32 reg_type = sljit_has_cpu_feature(SLJIT_HAS_AVX2) ? SLJIT_SIMD_REG_256 : SLJIT_SIMD_REG_128; */ sljit_s32 reg_type = SLJIT_SIMD_REG_128; - sljit_s32 value; struct sljit_label *start; #if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 struct sljit_label *restart; @@ -370,7 +369,7 @@ add_jump(compiler, &common->failed_match, partial_quit[0]); /* First part (unaligned start) */ - value = SLJIT_SIMD_REG_128 | SLJIT_SIMD_ELEM_32 | SLJIT_SIMD_LANE_ZERO; + sljit_s32 value = SLJIT_SIMD_REG_128 | SLJIT_SIMD_ELEM_32 | SLJIT_SIMD_LANE_ZERO; sljit_emit_simd_lane_mov(compiler, value, SLJIT_VR1, 0, SLJIT_IMM, character_to_int32(char1 | bit)); @@ -585,7 +584,6 @@ sljit_u32 max_unit = (PCRE2_UCHAR) ~(sljit_u32)0; sljit_u32 sign_max = max_unit >> 1; sljit_u32 span; - sljit_s32 value; int count, k; /* Three registers for the scan itself, and two more for the constants of @@ -631,7 +629,7 @@ /* Load the constants of every range, two registers apiece from VR3 upwards, of which a single character needs only the first. */ - value = SLJIT_SIMD_REG_128 | SLJIT_SIMD_ELEM_32 | SLJIT_SIMD_LANE_ZERO; + sljit_s32 value = SLJIT_SIMD_REG_128 | SLJIT_SIMD_ELEM_32 | SLJIT_SIMD_LANE_ZERO; for (k = 0; k < count; k++) { @@ -758,7 +756,6 @@ /* The AVX2 code path is currently disabled. */ /* sljit_s32 reg_type = sljit_has_cpu_feature(SLJIT_HAS_AVX2) ? SLJIT_SIMD_REG_256 : SLJIT_SIMD_REG_128; */ sljit_s32 reg_type = SLJIT_SIMD_REG_128; - sljit_s32 value; struct sljit_label *start; struct sljit_jump *quit; jump_list *not_found = NULL; @@ -789,7 +786,7 @@ /* First part (unaligned start) */ - value = SLJIT_SIMD_REG_128 | SLJIT_SIMD_ELEM_32 | SLJIT_SIMD_LANE_ZERO; + sljit_s32 value = SLJIT_SIMD_REG_128 | SLJIT_SIMD_ELEM_32 | SLJIT_SIMD_LANE_ZERO; sljit_emit_simd_lane_mov(compiler, value, SLJIT_VR1, 0, SLJIT_IMM, character_to_int32(char1 | bit)); @@ -883,7 +880,6 @@ /* The AVX2 code path is currently disabled. */ /* sljit_s32 reg_type = sljit_has_cpu_feature(SLJIT_HAS_AVX2) ? SLJIT_SIMD_REG_256 : SLJIT_SIMD_REG_128; */ sljit_s32 reg_type = SLJIT_SIMD_REG_128; - sljit_s32 value; vector_compare_type compare1_type = vector_compare_match1; vector_compare_type compare2_type = vector_compare_match1; sljit_u32 bit1 = 0; @@ -944,7 +940,7 @@ } } - value = SLJIT_SIMD_REG_128 | SLJIT_SIMD_ELEM_32 | SLJIT_SIMD_LANE_ZERO; + sljit_s32 value = SLJIT_SIMD_REG_128 | SLJIT_SIMD_ELEM_32 | SLJIT_SIMD_LANE_ZERO; sljit_emit_simd_lane_mov(compiler, value, SLJIT_VR2, 0, TMP1, 0); if (char1a != char1b) @@ -1233,7 +1229,6 @@ sljit_s32 offset) { DEFINE_COMPILER; - sljit_u32 instruction; struct sljit_label *start; #if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 struct sljit_label *restart; @@ -1292,7 +1287,7 @@ tmp_ind); /* SHRN */ - instruction = 0x0f0c8400 | (data_ind << 5) | data_ind; + sljit_u32 instruction = 0x0f0c8400 | (data_ind << 5) | data_ind; sljit_emit_op_custom(compiler, &instruction, sizeof(sljit_u32)); sljit_emit_simd_lane_mov(compiler, SLJIT_SIMD_STORE | SLJIT_SIMD_REG_128 | SLJIT_SIMD_ELEM_64, @@ -1370,7 +1365,6 @@ fast_requested_char_simd(compiler_common *common, PCRE2_UCHAR char1, PCRE2_UCHAR char2) { DEFINE_COMPILER; - sljit_u32 instruction; struct sljit_label *start; struct sljit_jump *quit; jump_list *not_found = NULL; @@ -1417,7 +1411,7 @@ tmp_ind); /* SHRN */ - instruction = 0x0f0c8400 | (data_ind << 5) | data_ind; + sljit_u32 instruction = 0x0f0c8400 | (data_ind << 5) | data_ind; sljit_emit_op_custom(compiler, &instruction, sizeof(sljit_u32)); sljit_emit_simd_lane_mov(compiler, SLJIT_SIMD_STORE | SLJIT_SIMD_REG_128 | SLJIT_SIMD_ELEM_64, @@ -3024,7 +3018,6 @@ sljit_s32 data, sljit_s32 cmp1, sljit_s32 cmp2, sljit_s32 tmp) { sljit_s32 dst_ind = sljit_get_register_index(SLJIT_GP_REGISTER, dst); - sljit_s32 tmp_ind; if (compare_type != vector_compare_match2) { @@ -3044,7 +3037,7 @@ } /* match2: compare against both chars, OR the masks. */ - tmp_ind = sljit_get_register_index(SLJIT_GP_REGISTER, tmp); + sljit_s32 tmp_ind = sljit_get_register_index(SLJIT_GP_REGISTER, tmp); OP2(SLJIT_XOR, tmp, 0, data, 0, cmp2, 0); emit_alpha_cmpbge(compiler, 31, tmp_ind, tmp_ind);
diff --git a/src/pcre2_jit_test.c b/src/pcre2_jit_test.c index 6528443..00954a0 100644 --- a/src/pcre2_jit_test.c +++ b/src/pcre2_jit_test.c
@@ -2295,7 +2295,7 @@ { pcre2_code_8 *code; int result, errorcode; - PCRE2_SIZE length, erroroffset; + PCRE2_SIZE erroroffset; PCRE2_SIZE *ovector = pcre2_get_ovector_pointer_8(mdata); if (current->pattern[i] == NULL) @@ -2317,7 +2317,8 @@ return 0; } - length = (PCRE2_SIZE)(strlen(current->input) - current->skip_left - current->skip_right); + PCRE2_SIZE length = + (PCRE2_SIZE)(strlen(current->input) - current->skip_left - current->skip_right); if (current->jit_compile_options & PCRE2_JIT_COMPLETE) { @@ -2354,16 +2355,14 @@ invalid_utf8_regression_tests(void) { const struct invalid_utf8_regression_test_case *current; - pcre2_compile_context_8 *ccontext; - pcre2_match_data_8 *mdata; int total = 0, successful = 0; int result; printf("\nRunning invalid-utf8 JIT regression tests\n"); - ccontext = pcre2_compile_context_create_8(NULL); + pcre2_compile_context_8 *ccontext = pcre2_compile_context_create_8(NULL); pcre2_set_newline_8(ccontext, PCRE2_NEWLINE_ANY); - mdata = pcre2_match_data_create_8(4, NULL); + pcre2_match_data_8 *mdata = pcre2_match_data_create_8(4, NULL); for (current = invalid_utf8_regression_test_cases; current->pattern[0]; current++) { @@ -2526,8 +2525,7 @@ { pcre2_code_16 *code; int result, errorcode; - PCRE2_SIZE length, erroroffset; - const PCRE2_UCHAR16 *input; + PCRE2_SIZE erroroffset; PCRE2_SIZE *ovector = pcre2_get_ovector_pointer_16(mdata); if (current->pattern[i] == NULL) @@ -2549,8 +2547,8 @@ return 0; } - input = current->input; - length = 0; + const PCRE2_UCHAR16 *input = current->input; + PCRE2_SIZE length = 0; while (*input++ != 0) length++; @@ -2592,16 +2590,14 @@ invalid_utf16_regression_tests(void) { const struct invalid_utf16_regression_test_case *current; - pcre2_compile_context_16 *ccontext; - pcre2_match_data_16 *mdata; int total = 0, successful = 0; int result; printf("\nRunning invalid-utf16 JIT regression tests\n"); - ccontext = pcre2_compile_context_create_16(NULL); + pcre2_compile_context_16 *ccontext = pcre2_compile_context_create_16(NULL); pcre2_set_newline_16(ccontext, PCRE2_NEWLINE_ANY); - mdata = pcre2_match_data_create_16(4, NULL); + pcre2_match_data_16 *mdata = pcre2_match_data_create_16(4, NULL); for (current = invalid_utf16_regression_test_cases; current->pattern[0]; current++) { @@ -2731,8 +2727,7 @@ { pcre2_code_32 *code; int result, errorcode; - PCRE2_SIZE length, erroroffset; - const PCRE2_UCHAR32 *input; + PCRE2_SIZE erroroffset; PCRE2_SIZE *ovector = pcre2_get_ovector_pointer_32(mdata); if (current->pattern[i] == NULL) @@ -2754,8 +2749,8 @@ return 0; } - input = current->input; - length = 0; + const PCRE2_UCHAR32 *input = current->input; + PCRE2_SIZE length = 0; while (*input++ != 0) length++; @@ -2797,16 +2792,14 @@ invalid_utf32_regression_tests(void) { const struct invalid_utf32_regression_test_case *current; - pcre2_compile_context_32 *ccontext; - pcre2_match_data_32 *mdata; int total = 0, successful = 0; int result; printf("\nRunning invalid-utf32 JIT regression tests\n"); - ccontext = pcre2_compile_context_create_32(NULL); + pcre2_compile_context_32 *ccontext = pcre2_compile_context_create_32(NULL); pcre2_set_newline_32(ccontext, PCRE2_NEWLINE_ANY); - mdata = pcre2_match_data_create_32(4, NULL); + pcre2_match_data_32 *mdata = pcre2_match_data_create_32(4, NULL); for (current = invalid_utf32_regression_test_cases; current->pattern[0]; current++) {
diff --git a/src/pcre2_match.c b/src/pcre2_match.c index f0a3735..22e7ab5 100644 --- a/src/pcre2_match.c +++ b/src/pcre2_match.c
@@ -284,11 +284,6 @@ static int do_callout(heapframe *F, match_block *mb, PCRE2_SIZE *lengthptr) { - int rc; - PCRE2_SIZE save0, save1; - PCRE2_SIZE *callout_ovector; - pcre2_callout_block *cb; - *lengthptr = (*Fecode == OP_CALLOUT) ? PRIV(OP_lengths)[OP_CALLOUT] : GET(Fecode, 1 + 2 * LINK_SIZE); @@ -305,12 +300,12 @@ references such as Fovector[-2] are use directly, so we set up a separate pointer. */ - callout_ovector = (PCRE2_SIZE *)(Fovector)-2; + PCRE2_SIZE *callout_ovector = (PCRE2_SIZE *)(Fovector)-2; /* The cb->version, cb->subject, and cb->subject_length fields are set externally and never change. */ - cb = mb->cb; + pcre2_callout_block *cb = mb->cb; cb->capture_top = (uint32_t)Foffset_top / 2 + 1; cb->capture_last = Fcapture_last; cb->offset_vector = callout_ovector; @@ -335,10 +330,10 @@ cb->callout_string_length = *lengthptr - (1 + 4 * LINK_SIZE) - 2; } - save0 = callout_ovector[0]; - save1 = callout_ovector[1]; + PCRE2_SIZE save0 = callout_ovector[0]; + PCRE2_SIZE save1 = callout_ovector[1]; callout_ovector[0] = callout_ovector[1] = PCRE2_UNSET; - rc = mb->callout(cb, mb->callout_data); + int rc = mb->callout(cb, mb->callout_data); callout_ovector[0] = save0; callout_ovector[1] = save1; cb->callout_flags = 0; @@ -374,9 +369,6 @@ match_ref(PCRE2_SIZE offset, BOOL caseless, int caseopts, heapframe *F, match_block *mb, PCRE2_SIZE *lengthptr) { - PCRE2_SPTR p; - PCRE2_SIZE length; - PCRE2_SPTR eptr; PCRE2_SPTR eptr_start; #ifndef SUPPORT_UNICODE @@ -401,9 +393,9 @@ /* Separate the caseless and UTF cases for speed. */ - eptr = eptr_start = Feptr; - p = mb->start_subject + Fovector[offset]; - length = Fovector[offset + 1] - Fovector[offset]; + PCRE2_SPTR eptr = eptr_start = Feptr; + PCRE2_SPTR p = mb->start_subject + Fovector[offset]; + PCRE2_SIZE length = Fovector[offset + 1] - Fovector[offset]; PCRE2_ASSERT(eptr <= mb->end_subject); if (caseless) @@ -477,11 +469,10 @@ { for (; length > 0; length--) { - uint32_t cc, cp; if (eptr >= mb->end_subject) return 1; // Partial match - cc = *eptr; - cp = *p; + uint32_t cc = *eptr; + uint32_t cp = *p; if (TABLE_GET(cp, mb->lcc, cp) != TABLE_GET(cc, mb->lcc, cc)) return -1; // No match p++; @@ -545,8 +536,8 @@ offset 0 is reserved for the full match. */ PCRE2_SIZE offset = 2; PCRE2_SIZE offset_top = Foffset_top + 2; - PCRE2_SIZE diff; PCRE2_SPTR ecode = Fecode; + PCRE2_SIZE diff; do { @@ -717,13 +708,10 @@ { /* Frame-handling variables */ - heapframe *F; // Current frame pointer heapframe *N = NULL; // Temporary frame pointers heapframe *P = NULL; - heapframe *frames_top; // End of frames vector heapframe *assert_accept_frame = NULL; // For passing back a frame with captures - PCRE2_SIZE frame_copy_size; // Amount to copy when creating a new frame /* Local variables that do not need to be preserved over calls to RMATCH(). */ @@ -742,7 +730,6 @@ uint32_t fc; // Character values uint32_t number; // Used for group and other numbers uint32_t reptype = 0; // Type of repetition (0 to avoid compiler warning) - uint32_t group_frame_type; // Specifies type for new group frames BOOL condition; // Used in conditional groups BOOL cur_is_word; // Used in "word" tests @@ -760,12 +747,14 @@ /* This is the length of the last part of a backtracking frame that must be copied when a new frame is created. */ - frame_copy_size = frame_size - offsetof(heapframe, eptr); + PCRE2_SIZE frame_copy_size = + frame_size - offsetof(heapframe, eptr); // Amount to copy when creating a new frame /* Set up the first frame and the end of the frames vector. */ - F = match_data->heapframes; - frames_top = (heapframe *)((char *)F + match_data->heapframes_size); + heapframe *F = match_data->heapframes; // Current frame pointer + heapframe *frames_top = + (heapframe *)((char *)F + match_data->heapframes_size); // End of frames vector Frdepth = 0; // "Recursion" depth Fcapture_last = 0; // Number of most recent capture @@ -774,7 +763,7 @@ Fmark = NULL; // Most recent mark Foffset_top = 0; // End of captures within the frame Flast_group_offset = PCRE2_UNSET; // Saved frame of most recent group - group_frame_type = 0; // Not a start of group frame + uint32_t group_frame_type = 0; // Specifies type for new group frames; not a start of group frame goto NEW_FRAME; // Start processing with this frame /* Come back here when we want to create a new frame for remembering a @@ -788,7 +777,6 @@ N = (heapframe *)((char *)F + frame_size); if ((heapframe *)((char *)N + frame_size) >= frames_top) { - heapframe *new; PCRE2_SIZE newsize; PCRE2_SIZE usedsize = (char *)N - (char *)(match_data->heapframes); @@ -825,7 +813,7 @@ if (newsize - usedsize < frame_size) return PCRE2_ERROR_HEAPLIMIT; - new = match_data->memctl.malloc(newsize, match_data->memctl.memory_data); + heapframe *new = match_data->memctl.malloc(newsize, match_data->memctl.memory_data); if (new == NULL) return PCRE2_ERROR_NOMEMORY; memcpy(new, match_data->heapframes, usedsize); @@ -1293,8 +1281,8 @@ #ifdef SUPPORT_UNICODE if (utf) { - uint32_t ch; Fecode++; + uint32_t ch; GETCHARINC(ch, Fecode); GETCHARINC(fc, Feptr); if (ch == fc) @@ -1316,9 +1304,8 @@ else if (ucp) { - uint32_t ch; fc = *Feptr++; - ch = Fecode[1]; + uint32_t ch = Fecode[1]; Fecode += 2; if (ch == fc) @@ -1604,14 +1591,13 @@ for (i = 1; i <= Lmin; i++) { - uint32_t cc; // Faster than PCRE2_UCHAR if (Feptr >= mb->end_subject) { SCHECK_PARTIAL(); RRETURN(MATCH_NOMATCH); } - cc = *Feptr; + uint32_t cc = *Feptr; // Faster than PCRE2_UCHAR if (Lc != cc && Loc != cc) RRETURN(MATCH_NOMATCH); Feptr++; @@ -1624,7 +1610,6 @@ { for (;;) { - uint32_t cc; // Faster than PCRE2_UCHAR RMATCH(Fecode, RM25); if (rrc != MATCH_NOMATCH) RRETURN(rrc); @@ -1636,7 +1621,7 @@ RRETURN(MATCH_NOMATCH); } - cc = *Feptr; + uint32_t cc = *Feptr; // Faster than PCRE2_UCHAR if (Lc != cc && Loc != cc) RRETURN(MATCH_NOMATCH); Feptr++; @@ -1650,14 +1635,13 @@ Lstart_eptr = Feptr; for (i = Lmin; i < Lmax; i++) { - uint32_t cc; // Faster than PCRE2_UCHAR if (Feptr >= mb->end_subject) { SCHECK_PARTIAL(); break; } - cc = *Feptr; + uint32_t cc = *Feptr; // Faster than PCRE2_UCHAR if (Lc != cc && Loc != cc) break; Feptr++; @@ -1873,7 +1857,6 @@ #ifdef SUPPORT_UNICODE if (utf) { - uint32_t d; for (i = 1; i <= Lmin; i++) { if (Feptr >= mb->end_subject) @@ -1882,6 +1865,7 @@ RRETURN(MATCH_NOMATCH); } + uint32_t d; GETCHARINC(d, Feptr); if (Lc == d || Loc == d) RRETURN(MATCH_NOMATCH); @@ -1914,7 +1898,6 @@ #ifdef SUPPORT_UNICODE if (utf) { - uint32_t d; for (;;) { RMATCH(Fecode, RM204); @@ -1928,6 +1911,7 @@ RRETURN(MATCH_NOMATCH); } + uint32_t d; GETCHARINC(d, Feptr); if (Lc == d || Loc == d) RRETURN(MATCH_NOMATCH); @@ -1969,7 +1953,6 @@ #ifdef SUPPORT_UNICODE if (utf) { - uint32_t d; for (i = Lmin; i < Lmax; i++) { int len = 1; @@ -1979,6 +1962,7 @@ break; } + uint32_t d; GETCHARLEN(d, Feptr, len); if (Lc == d || Loc == d) break; @@ -2044,7 +2028,6 @@ #ifdef SUPPORT_UNICODE if (utf) { - uint32_t d; for (i = 1; i <= Lmin; i++) { if (Feptr >= mb->end_subject) @@ -2053,6 +2036,7 @@ RRETURN(MATCH_NOMATCH); } + uint32_t d; GETCHARINC(d, Feptr); if (Lc == d) RRETURN(MATCH_NOMATCH); @@ -2083,7 +2067,6 @@ #ifdef SUPPORT_UNICODE if (utf) { - uint32_t d; for (;;) { RMATCH(Fecode, RM206); @@ -2097,6 +2080,7 @@ RRETURN(MATCH_NOMATCH); } + uint32_t d; GETCHARINC(d, Feptr); if (Lc == d) RRETURN(MATCH_NOMATCH); @@ -2136,7 +2120,6 @@ #ifdef SUPPORT_UNICODE if (utf) { - uint32_t d; for (i = Lmin; i < Lmax; i++) { int len = 1; @@ -2146,6 +2129,7 @@ break; } + uint32_t d; GETCHARLEN(d, Feptr, len); if (Lc == d) break; @@ -3290,7 +3274,6 @@ case PT_LAMP: for (i = 1; i <= Lmin; i++) { - int chartype; if (Feptr >= mb->end_subject) { SCHECK_PARTIAL(); @@ -3298,7 +3281,7 @@ } GETCHARINCTEST(fc, Feptr); - chartype = UCD_CHARTYPE(fc); + int chartype = UCD_CHARTYPE(fc); if ((chartype == ucp_Lu || chartype == ucp_Ll || chartype == ucp_Lt) == notmatch) RRETURN(MATCH_NOMATCH); } @@ -3357,7 +3340,6 @@ for (i = 1; i <= Lmin; i++) { BOOL ok; - const ucd_record *prop; if (Feptr >= mb->end_subject) { SCHECK_PARTIAL(); @@ -3365,7 +3347,7 @@ } GETCHARINCTEST(fc, Feptr); - prop = GET_UCD(fc); + const ucd_record *prop = GET_UCD(fc); ok = (prop->script == Lpropvalue || MAPBIT(PRIV(ucd_script_sets) + UCD_SCRIPTX_PROP(prop), Lpropvalue) != 0); if (ok == notmatch) @@ -3377,7 +3359,6 @@ case PT_ALNUM: for (i = 1; i <= Lmin; i++) { - int category; if (Feptr >= mb->end_subject) { SCHECK_PARTIAL(); @@ -3385,7 +3366,7 @@ } GETCHARINCTEST(fc, Feptr); - category = UCD_CATEGORY(fc); + int category = UCD_CATEGORY(fc); if ((category == ucp_L || category == ucp_N) == notmatch) RRETURN(MATCH_NOMATCH); } @@ -3427,7 +3408,6 @@ case PT_WORD: for (i = 1; i <= Lmin; i++) { - int chartype, category; if (Feptr >= mb->end_subject) { SCHECK_PARTIAL(); @@ -3435,8 +3415,8 @@ } GETCHARINCTEST(fc, Feptr); - chartype = UCD_CHARTYPE(fc); - category = PRIV(ucp_gentype)[chartype]; + int chartype = UCD_CHARTYPE(fc); + int category = PRIV(ucp_gentype)[chartype]; if ((category == ucp_L || category == ucp_N || chartype == ucp_Mn || chartype == ucp_Pc) == notmatch) RRETURN(MATCH_NOMATCH); @@ -3447,7 +3427,6 @@ case PT_CLIST: for (i = 1; i <= Lmin; i++) { - const uint32_t *cp; if (Feptr >= mb->end_subject) { SCHECK_PARTIAL(); @@ -3463,7 +3442,7 @@ RRETURN(MATCH_NOMATCH); } #endif - cp = PRIV(ucd_caseless_sets) + Lpropvalue; + const uint32_t *cp = PRIV(ucd_caseless_sets) + Lpropvalue; for (;;) { if (fc < *cp) @@ -3520,8 +3499,6 @@ case PT_BOOL: for (i = 1; i <= Lmin; i++) { - BOOL ok; - const ucd_record *prop; if (Feptr >= mb->end_subject) { SCHECK_PARTIAL(); @@ -3529,8 +3506,8 @@ } GETCHARINCTEST(fc, Feptr); - prop = GET_UCD(fc); - ok = MAPBIT(PRIV(ucd_boolprop_sets) + UCD_BPROPS_PROP(prop), Lpropvalue) != 0; + const ucd_record *prop = GET_UCD(fc); + BOOL ok = MAPBIT(PRIV(ucd_boolprop_sets) + UCD_BPROPS_PROP(prop), Lpropvalue) != 0; if (ok == notmatch) RRETURN(MATCH_NOMATCH); } @@ -3766,14 +3743,13 @@ case OP_DIGIT: for (i = 1; i <= Lmin; i++) { - uint32_t cc; if (Feptr >= mb->end_subject) { SCHECK_PARTIAL(); RRETURN(MATCH_NOMATCH); } - cc = *Feptr; + uint32_t cc = *Feptr; if (cc >= 128 || (mb->ctypes[cc] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH); Feptr++; @@ -3785,14 +3761,13 @@ case OP_NOT_WHITESPACE: for (i = 1; i <= Lmin; i++) { - uint32_t cc; if (Feptr >= mb->end_subject) { SCHECK_PARTIAL(); RRETURN(MATCH_NOMATCH); } - cc = *Feptr; + uint32_t cc = *Feptr; if (cc < 128 && (mb->ctypes[cc] & ctype_space) != 0) RRETURN(MATCH_NOMATCH); Feptr++; @@ -3804,14 +3779,13 @@ case OP_WHITESPACE: for (i = 1; i <= Lmin; i++) { - uint32_t cc; if (Feptr >= mb->end_subject) { SCHECK_PARTIAL(); RRETURN(MATCH_NOMATCH); } - cc = *Feptr; + uint32_t cc = *Feptr; if (cc >= 128 || (mb->ctypes[cc] & ctype_space) == 0) RRETURN(MATCH_NOMATCH); Feptr++; @@ -3823,14 +3797,13 @@ case OP_NOT_WORDCHAR: for (i = 1; i <= Lmin; i++) { - uint32_t cc; if (Feptr >= mb->end_subject) { SCHECK_PARTIAL(); RRETURN(MATCH_NOMATCH); } - cc = *Feptr; + uint32_t cc = *Feptr; if (cc < 128 && (mb->ctypes[cc] & ctype_word) != 0) RRETURN(MATCH_NOMATCH); Feptr++; @@ -3842,14 +3815,13 @@ case OP_WORDCHAR: for (i = 1; i <= Lmin; i++) { - uint32_t cc; if (Feptr >= mb->end_subject) { SCHECK_PARTIAL(); RRETURN(MATCH_NOMATCH); } - cc = *Feptr; + uint32_t cc = *Feptr; if (cc >= 128 || (mb->ctypes[cc] & ctype_word) == 0) RRETURN(MATCH_NOMATCH); Feptr++; @@ -4177,7 +4149,6 @@ case PT_LAMP: for (;;) { - int chartype; RMATCH(Fecode, RM208); if (rrc != MATCH_NOMATCH) RRETURN(rrc); @@ -4190,7 +4161,7 @@ } GETCHARINCTEST(fc, Feptr); - chartype = UCD_CHARTYPE(fc); + int chartype = UCD_CHARTYPE(fc); if ((chartype == ucp_Lu || chartype == ucp_Ll || chartype == ucp_Lt) == (Lctype == OP_NOTPROP)) RRETURN(MATCH_NOMATCH); @@ -4265,7 +4236,6 @@ for (;;) { BOOL ok; - const ucd_record *prop; RMATCH(Fecode, RM224); if (rrc != MATCH_NOMATCH) RRETURN(rrc); @@ -4278,7 +4248,7 @@ } GETCHARINCTEST(fc, Feptr); - prop = GET_UCD(fc); + const ucd_record *prop = GET_UCD(fc); ok = (prop->script == Lpropvalue || MAPBIT(PRIV(ucd_script_sets) + UCD_SCRIPTX_PROP(prop), Lpropvalue) != 0); if (ok == (Lctype == OP_NOTPROP)) @@ -4290,7 +4260,6 @@ case PT_ALNUM: for (;;) { - int category; RMATCH(Fecode, RM212); if (rrc != MATCH_NOMATCH) RRETURN(rrc); @@ -4303,7 +4272,7 @@ } GETCHARINCTEST(fc, Feptr); - category = UCD_CATEGORY(fc); + int category = UCD_CATEGORY(fc); if ((category == ucp_L || category == ucp_N) == (Lctype == OP_NOTPROP)) RRETURN(MATCH_NOMATCH); } @@ -4350,7 +4319,6 @@ case PT_WORD: for (;;) { - int chartype, category; RMATCH(Fecode, RM214); if (rrc != MATCH_NOMATCH) RRETURN(rrc); @@ -4363,8 +4331,8 @@ } GETCHARINCTEST(fc, Feptr); - chartype = UCD_CHARTYPE(fc); - category = PRIV(ucp_gentype)[chartype]; + int chartype = UCD_CHARTYPE(fc); + int category = PRIV(ucp_gentype)[chartype]; if ((category == ucp_L || category == ucp_N || chartype == ucp_Mn || chartype == ucp_Pc) == (Lctype == OP_NOTPROP)) RRETURN(MATCH_NOMATCH); @@ -4375,7 +4343,6 @@ case PT_CLIST: for (;;) { - const uint32_t *cp; RMATCH(Fecode, RM215); if (rrc != MATCH_NOMATCH) RRETURN(rrc); @@ -4396,7 +4363,7 @@ RRETURN(MATCH_NOMATCH); } #endif - cp = PRIV(ucd_caseless_sets) + Lpropvalue; + const uint32_t *cp = PRIV(ucd_caseless_sets) + Lpropvalue; for (;;) { if (fc < *cp) @@ -4463,8 +4430,6 @@ case PT_BOOL: for (;;) { - BOOL ok; - const ucd_record *prop; RMATCH(Fecode, RM222); if (rrc != MATCH_NOMATCH) RRETURN(rrc); @@ -4477,8 +4442,8 @@ } GETCHARINCTEST(fc, Feptr); - prop = GET_UCD(fc); - ok = MAPBIT(PRIV(ucd_boolprop_sets) + UCD_BPROPS_PROP(prop), Lpropvalue) != 0; + const ucd_record *prop = GET_UCD(fc); + BOOL ok = MAPBIT(PRIV(ucd_boolprop_sets) + UCD_BPROPS_PROP(prop), Lpropvalue) != 0; if (ok == (Lctype == OP_NOTPROP)) RRETURN(MATCH_NOMATCH); } @@ -4856,7 +4821,6 @@ case PT_LAMP: for (i = Lmin; i < Lmax; i++) { - int chartype; int len = 1; if (Feptr >= mb->end_subject) { @@ -4865,7 +4829,7 @@ } GETCHARLENTEST(fc, Feptr, len); - chartype = UCD_CHARTYPE(fc); + int chartype = UCD_CHARTYPE(fc); if ((chartype == ucp_Lu || chartype == ucp_Ll || chartype == ucp_Lt) == notmatch) break; Feptr += len; @@ -4931,7 +4895,6 @@ for (i = Lmin; i < Lmax; i++) { BOOL ok; - const ucd_record *prop; int len = 1; if (Feptr >= mb->end_subject) { @@ -4940,7 +4903,7 @@ } GETCHARLENTEST(fc, Feptr, len); - prop = GET_UCD(fc); + const ucd_record *prop = GET_UCD(fc); ok = (prop->script == Lpropvalue || MAPBIT(PRIV(ucd_script_sets) + UCD_SCRIPTX_PROP(prop), Lpropvalue) != 0); if (ok == notmatch) @@ -4953,7 +4916,6 @@ case PT_ALNUM: for (i = Lmin; i < Lmax; i++) { - int category; int len = 1; if (Feptr >= mb->end_subject) { @@ -4962,7 +4924,7 @@ } GETCHARLENTEST(fc, Feptr, len); - category = UCD_CATEGORY(fc); + int category = UCD_CATEGORY(fc); if ((category == ucp_L || category == ucp_N) == notmatch) break; Feptr += len; @@ -5009,7 +4971,6 @@ case PT_WORD: for (i = Lmin; i < Lmax; i++) { - int chartype, category; int len = 1; if (Feptr >= mb->end_subject) { @@ -5018,8 +4979,8 @@ } GETCHARLENTEST(fc, Feptr, len); - chartype = UCD_CHARTYPE(fc); - category = PRIV(ucp_gentype)[chartype]; + int chartype = UCD_CHARTYPE(fc); + int category = PRIV(ucp_gentype)[chartype]; if ((category == ucp_L || category == ucp_N || chartype == ucp_Mn || chartype == ucp_Pc) == notmatch) break; @@ -5116,8 +5077,6 @@ case PT_BOOL: for (i = Lmin; i < Lmax; i++) { - BOOL ok; - const ucd_record *prop; int len = 1; if (Feptr >= mb->end_subject) { @@ -5126,8 +5085,8 @@ } GETCHARLENTEST(fc, Feptr, len); - prop = GET_UCD(fc); - ok = MAPBIT(PRIV(ucd_boolprop_sets) + UCD_BPROPS_PROP(prop), Lpropvalue) != 0; + const ucd_record *prop = GET_UCD(fc); + BOOL ok = MAPBIT(PRIV(ucd_boolprop_sets) + UCD_BPROPS_PROP(prop), Lpropvalue) != 0; if (ok == notmatch) break; Feptr += len; @@ -5197,7 +5156,7 @@ for (;;) { - int lgb, rgb; + int lgb; PCRE2_SPTR fptr; if (Feptr <= Lstart_eptr) @@ -5221,7 +5180,7 @@ GETCHAR(fc, Feptr); } - rgb = UCD_GRAPHBREAK(fc); + int rgb = UCD_GRAPHBREAK(fc); for (;;) { @@ -6135,13 +6094,11 @@ case OP_BRAZERO: { - PCRE2_SPTR next_ecode; - Fecode++; RMATCH(Fecode, RM9); if (rrc != MATCH_NOMATCH) RRETURN(rrc); - next_ecode = Fecode; + PCRE2_SPTR next_ecode = Fecode; do next_ecode += GET(next_ecode, 1); while (*next_ecode == OP_ALT); @@ -6152,10 +6109,8 @@ case OP_BRAMINZERO: { - PCRE2_SPTR next_ecode; - Fecode++; - next_ecode = Fecode; + PCRE2_SPTR next_ecode = Fecode; do next_ecode += GET(next_ecode, 1); while (*next_ecode == OP_ALT); @@ -6409,11 +6364,9 @@ for (;;) { - PCRE2_SPTR next_ecode; - group_frame_type = Lframe_type; RMATCH(Lstart_branch + PRIV(OP_lengths)[*Lstart_branch], RM11); - next_ecode = Lstart_branch + GET(Lstart_branch, 1); + PCRE2_SPTR next_ecode = Lstart_branch + GET(Lstart_branch, 1); /* Handle backtracking verbs, which are defined in a range that can easily be tested for. PCRE does not allow THEN, SKIP, PRUNE or COMMIT to @@ -7735,11 +7688,8 @@ const pcre2_real_code *re = (const pcre2_real_code *)code; uint32_t original_options = options; - BOOL anchored; - BOOL firstline; BOOL has_first_cu = FALSE; BOOL has_req_cu = FALSE; - BOOL startline; #if PCRE2_CODE_UNIT_WIDTH == 8 PCRE2_SPTR memchr_found_first_cu; @@ -7755,9 +7705,6 @@ PCRE2_SPTR original_subject = subject; PCRE2_SPTR bumpalong_limit; PCRE2_SPTR end_subject; - PCRE2_SPTR true_end_subject; - PCRE2_SPTR start_match; - PCRE2_SPTR req_cu_ptr; PCRE2_SPTR start_partial; PCRE2_SPTR match_partial; @@ -7768,7 +7715,6 @@ #ifdef SUPPORT_UNICODE BOOL ucp = FALSE; - BOOL allow_invalid; uint32_t fragment_options = 0; #endif /* SUPPORT_UNICODE */ @@ -7796,14 +7742,14 @@ if ((options & ~PUBLIC_MATCH_OPTIONS) != 0) return match_data->rc = PCRE2_ERROR_BADOPTION; - start_match = subject + start_offset; - req_cu_ptr = start_match - 1; + PCRE2_SPTR start_match = subject + start_offset; + PCRE2_SPTR req_cu_ptr = start_match - 1; if (length == PCRE2_ZERO_TERMINATED) { length = PRIV(strlen)(subject); } - true_end_subject = end_subject = subject + length; + PCRE2_SPTR true_end_subject = end_subject = subject + length; if (start_offset > length) return match_data->rc = PCRE2_ERROR_BADOFFSET; @@ -7843,7 +7789,7 @@ #ifdef SUPPORT_UNICODE utf = (re->overall_options & PCRE2_UTF) != 0; - allow_invalid = (re->overall_options & PCRE2_MATCH_INVALID_UTF) != 0; + BOOL allow_invalid = (re->overall_options & PCRE2_MATCH_INVALID_UTF) != 0; ucp = (re->overall_options & PCRE2_UCP) != 0; #endif /* SUPPORT_UNICODE */ @@ -8142,9 +8088,9 @@ mb->memctl = mcontext->memctl; } - anchored = ((re->overall_options | options) & PCRE2_ANCHORED) != 0; - firstline = !anchored && (re->overall_options & PCRE2_FIRSTLINE) != 0; - startline = (re->flags & PCRE2_STARTLINE) != 0; + BOOL anchored = ((re->overall_options | options) & PCRE2_ANCHORED) != 0; + BOOL firstline = !anchored && (re->overall_options & PCRE2_FIRSTLINE) != 0; + BOOL startline = (re->flags & PCRE2_STARTLINE) != 0; bumpalong_limit = (mcontext->offset_limit == PCRE2_UNSET) ? true_end_subject : subject + mcontext->offset_limit; @@ -8600,8 +8546,6 @@ if (mb->partial == 0) { - PCRE2_SPTR p; - /* The minimum matching length is a lower bound; no string of that length may actually match the pattern. Although the value is, strictly, in characters, we treat it as code units to avoid spending too much time in @@ -8635,7 +8579,7 @@ string is sufficiently long, but it's worth searching a lot more for unanchored patterns. */ - p = start_match + (has_first_cu ? 1 : 0); + PCRE2_SPTR p = start_match + (has_first_cu ? 1 : 0); if (has_req_cu && p > req_cu_ptr) { PCRE2_SIZE check_length = end_subject - start_match;
diff --git a/src/pcre2_study.c b/src/pcre2_study.c index 3187add..716fe8a 100644 --- a/src/pcre2_study.c +++ b/src/pcre2_study.c
@@ -137,7 +137,6 @@ for (;;) { int d, min, recno; - PCRE2_UCHAR op; PCRE2_SPTR cs, ce; if (branchlength >= (int)UINT16_MAX) @@ -146,7 +145,7 @@ cc = nextbranch; } - op = *cc; + PCRE2_UCHAR op = *cc; switch (op) { case OP_COND: @@ -1004,21 +1003,19 @@ static void study_char_list(PCRE2_SPTR code, uint8_t *start_bitmap, const uint8_t *char_lists_end) { - uint32_t type, list_ind; uint32_t char_list_add = XCL_CHAR_LIST_LOW_16_ADD; uint32_t range_start = ~(uint32_t)0, range_end = 0; - const uint8_t *next_char; PCRE2_UCHAR start_buffer[6], end_buffer[6]; PCRE2_UCHAR start, end; /* Only needed in 8-bit mode at the moment. */ - type = (uint32_t)(code[0] << 8) | code[1]; + uint32_t type = (uint32_t)(code[0] << 8) | code[1]; code += 2; /* Align characters. */ - next_char = char_lists_end - (GET(code, 0) << 1); + const uint8_t *next_char = char_lists_end - (GET(code, 0) << 1); type &= XCL_TYPE_MASK; - list_ind = 0; + uint32_t list_ind = 0; if ((type & XCL_BEGIN_WITH_RANGE) != 0) range_start = XCL_CHAR_LIST_LOW_16_START; @@ -2021,13 +2018,12 @@ PRIV(study)(pcre2_real_code *re) { int count = 0; - PCRE2_UCHAR *code; BOOL utf = (re->overall_options & PCRE2_UTF) != 0; BOOL ucp = (re->overall_options & PCRE2_UCP) != 0; /* Find start of compiled code */ - code = (PCRE2_UCHAR *)((uint8_t *)re + re->code_start); + PCRE2_UCHAR *code = (PCRE2_UCHAR *)((uint8_t *)re + re->code_start); /* For a pattern that has a first code unit, or a multiline pattern that matches only at "line start", there is no point in seeking a list of starting @@ -2066,7 +2062,6 @@ uint8_t x = *p; if (x != 0) { - int c; uint8_t y = x & (~x + 1); // Least significant bit if (y != x) goto DONE; // More than one bit set @@ -2081,7 +2076,7 @@ /* Compute the character value */ - c = i; + int c = i; switch (x) { case 1: @@ -2192,10 +2187,9 @@ if ((re->flags & (PCRE2_MATCH_EMPTY | PCRE2_HASACCEPT)) == 0 && re->top_backref <= MAX_CACHE_BACKREF) { - int min; int backref_cache[MAX_CACHE_BACKREF + 1]; backref_cache[0] = 0; // Highest one that is set - min = find_minlength(re, code, code, utf, NULL, &count, backref_cache); + int min = find_minlength(re, code, code, utf, NULL, &count, backref_cache); switch (min) { case -1: // \C in UTF mode or over-complex regex
diff --git a/src/pcre2_xclass.c b/src/pcre2_xclass.c index b69b782..901213b 100644 --- a/src/pcre2_xclass.c +++ b/src/pcre2_xclass.c
@@ -70,7 +70,6 @@ PCRE2_UCHAR t; BOOL not_negated = (*data & XCL_NOT) == 0; uint32_t type, max_index, min_index, value; - const uint8_t *next_char; #if PCRE2_CODE_UNIT_WIDTH == 8 /* In 8 bit mode, this must always be TRUE. Help the compiler to know that. */ @@ -316,7 +315,7 @@ #endif /* CODE_UNIT_WIDTH */ /* Align characters. */ - next_char = char_lists_end - (GET(data, 0) << 1); + const uint8_t *next_char = char_lists_end - (GET(data, 0) << 1); type &= XCL_TYPE_MASK; /* Alignment check. */ @@ -463,12 +462,11 @@ BOOL utf) { PCRE2_SPTR ptr = data_start; - PCRE2_UCHAR flags; uint32_t stack = 0; int stack_depth = 0; PCRE2_ASSERT(data_start < data_end); - flags = *ptr++; + PCRE2_UCHAR flags = *ptr++; PCRE2_ASSERT((flags & ECL_MAP) == 0 || (data_end - ptr) >= 32 / (int)sizeof(PCRE2_UCHAR)); /* Code points < 256 are matched against a bitmap, if one is present.
diff --git a/src/pcre2grep.c b/src/pcre2grep.c index ce5a067..43e3fca 100644 --- a/src/pcre2grep.c +++ b/src/pcre2grep.c
@@ -629,16 +629,14 @@ parse_grep_colors(const char *gc) { static char seq[16]; - const char *col; - uint32_t len; if (gc == NULL) return NULL; - col = strstr(gc, "ms="); + const char *col = strstr(gc, "ms="); if (col == NULL) col = strstr(gc, "mt="); if (col == NULL) return NULL; - len = 0; + uint32_t len = 0; col += 3; while (*col != ':' && *col != 0 && len < sizeof(seq) - 1) seq[len++] = *col++; @@ -1040,13 +1038,9 @@ static directory_type * opendirectory(char *filename) { - size_t len; - char *pattern; - directory_type *dir; - DWORD err; - len = strlen(filename); - pattern = (char *)malloc(len + 3); - dir = (directory_type *)malloc(sizeof(*dir)); + size_t len = strlen(filename); + char *pattern = (char *)malloc(len + 3); + directory_type *dir = (directory_type *)malloc(sizeof(*dir)); if ((pattern == NULL) || (dir == NULL)) { fprintf(stderr, "pcre2grep: malloc failed\n"); @@ -1066,7 +1060,7 @@ return dir; } - err = GetLastError(); + DWORD err = GetLastError(); free(pattern); free(dir); errno = (err == ERROR_ACCESS_DENIED) ? EACCES : ENOENT; @@ -1698,7 +1692,6 @@ if (utf && c >= 0xc0) { - int gcii, gcss; extra = utf8_table4[c & 0x3f]; // Number of additional bytes if (endptr - p < 1 + extra) { @@ -1706,9 +1699,9 @@ return endptr; } - gcss = 6 * extra; + int gcss = 6 * extra; c = (c & utf8_table3[extra]) << gcss; - for (gcii = 1; gcii <= extra; gcii++) + for (int gcii = 1; gcii <= extra; gcii++) { gcss -= 6; c |= (p[gcii] & 0x3f) << gcss; @@ -1854,7 +1847,6 @@ c = *((unsigned char *)pp); if (c >= 0xc0) { - int gcii, gcss; extra = utf8_table4[c & 0x3f]; // Number of additional bytes if (p - pp < 1 + extra) { @@ -1862,9 +1854,9 @@ continue; } - gcss = 6 * extra; + int gcss = 6 * extra; c = (c & utf8_table3[extra]) << gcss; - for (gcii = 1; gcii <= extra; gcii++) + for (int gcii = 1; gcii <= extra; gcii++) { gcss -= 6; c |= (pp[gcii] & 0x3f) << gcss; @@ -2457,10 +2449,9 @@ case DDE_CAPTURE: if (value < capture_top) { - PCRE2_SIZE capturesize, start, end; value *= 2; - start = ovector[value]; - end = ovector[value + 1]; + PCRE2_SIZE start = ovector[value]; + PCRE2_SIZE end = ovector[value + 1]; /* The use of \K may make the end offset earlier than the start. In this situation, swap them round. */ @@ -2472,7 +2463,7 @@ end = temp; } - capturesize = end - start; + PCRE2_SIZE capturesize = end - start; if (capturesize > 0) { print_match(subject + start, capturesize); @@ -2572,12 +2563,7 @@ #ifdef SUPPORT_PCRE2GREP_CALLOUT_FORK PCRE2_SIZE argsvectorlen = 2; PCRE2_SIZE argslen = 1; - char *args; - char *argsptr; - char **argsvector; - char **argsvectorptr; #ifndef WIN32 - pid_t pid; #endif int result = 0; #endif /* SUPPORT_PCRE2GREP_CALLOUT_FORK */ @@ -2664,11 +2650,11 @@ /* Get memory for the argument vector and its strings. */ - args = (char *)malloc(argslen); + char *args = (char *)malloc(argslen); if (args == NULL) return 0; - argsvector = (char **)malloc(argsvectorlen * sizeof(char *)); + char **argsvector = (char **)malloc(argsvectorlen * sizeof(char *)); if (argsvector == NULL) { /* LCOV_EXCL_START */ @@ -2679,8 +2665,8 @@ /* Now reprocess the string and set up the arguments. */ - argsptr = args; - argsvectorptr = argsvector; + char *argsptr = args; + char **argsvectorptr = argsvector; *argsvectorptr++ = argsptr; length = calloutptr->callout_string_length; @@ -2704,10 +2690,9 @@ case DDE_CAPTURE: if (value < capture_top) { - PCRE2_SIZE capturesize, start, end; value *= 2; - start = ovector[value]; - end = ovector[value + 1]; + PCRE2_SIZE start = ovector[value]; + PCRE2_SIZE end = ovector[value + 1]; /* The use of \K may make the end offset earlier than the start. In this situation, swap them round. */ @@ -2719,7 +2704,7 @@ end = temp; } - capturesize = end - start; + PCRE2_SIZE capturesize = end - start; memcpy(argsptr, subject + start, capturesize); argsptr += capturesize; } @@ -2804,7 +2789,7 @@ #else /* Neither Windows nor VMS */ (void)fflush(stdout); - pid = fork(); + pid_t pid = fork(); if (pid == 0) { (void)execv(argsvector[0], argsvector); @@ -2905,9 +2890,6 @@ long int count_matched_lines = 0; char *lastmatchrestart = main_buffer; char *ptr = main_buffer; - char *endptr; - PCRE2_SIZE bufflength; - ptrdiff_t buffrc; BOOL binary = FALSE; BOOL endhyphenpending = FALSE; BOOL lines_printed = FALSE; @@ -2940,7 +2922,7 @@ input_line_buffered = FALSE; } - buffrc = fill_buffer(handle, frtype, main_buffer, bufsize, input_line_buffered); + ptrdiff_t buffrc = fill_buffer(handle, frtype, main_buffer, bufsize, input_line_buffered); #if defined SUPPORT_LIBZ if (frtype == FR_LIBZ && buffrc < 0) @@ -2951,8 +2933,8 @@ return 3; #endif - bufflength = (PCRE2_SIZE)buffrc; - endptr = main_buffer + bufflength; + PCRE2_SIZE bufflength = (PCRE2_SIZE)buffrc; + char *endptr = main_buffer + bufflength; /* Unless binary-files=text, see if we have a binary file. This uses the same rule as GNU grep, namely, a search for a binary zero byte near the start of the @@ -3016,12 +2998,11 @@ { if (bufthird < max_bufthird) { - char *new_buffer; PCRE2_SIZE new_bufthird = 2 * bufthird; if (new_bufthird > max_bufthird) new_bufthird = max_bufthird; - new_buffer = (char *)malloc(3 * new_bufthird); + char *new_buffer = (char *)malloc(3 * new_bufthird); if (new_buffer == NULL) { @@ -3155,8 +3136,6 @@ { if (!invert) { - PCRE2_SIZE oldstartoffset; - if (printname != NULL) fprintf(stdout, "%s%c", printname, printname_colon); if (number) @@ -3208,7 +3187,6 @@ { PCRE2_SIZE start = offsets[2 * n]; PCRE2_SIZE end = offsets[2 * n + 1]; - size_t plen; /* The use of \K may make the end offset earlier than the start. In this situation, swap them round. */ @@ -3220,7 +3198,7 @@ end = temp; } - plen = end - start; + size_t plen = end - start; if (plen > 0) { if (printed && om_separator != NULL) @@ -3248,7 +3226,7 @@ further on. */ startoffset = offsets[1]; // Restart after the match - oldstartoffset = pcre2_get_startchar(match_data); + PCRE2_SIZE oldstartoffset = pcre2_get_startchar(match_data); if (startoffset <= oldstartoffset) { if (oldstartoffset >= length) @@ -3398,7 +3376,6 @@ if ((multiline || do_colour) && !invert) { - int plength; PCRE2_SIZE endprevious; /* The use of \K may make the end offset earlier than the start. In @@ -3496,7 +3473,7 @@ and its line-ending characters (if they matched the pattern), so there may be no more to print. */ - plength = (int)((linelength + endlinelength) - endprevious); + int plength = (int)((linelength + endlinelength) - endprevious); if (plength > 0) FWRITE_IGNORE(ptr + endprevious, 1, plength, stdout); } @@ -3680,7 +3657,6 @@ int rc = 1; int frtype; void *handle; - char *lastcomp; FILE *in = NULL; // Ensure initialized #ifdef SUPPORT_LIBZ @@ -3692,12 +3668,9 @@ #endif #if defined SUPPORT_LIBZ || defined SUPPORT_LIBBZ2 - int pathlen; #endif #if defined NATIVE_ZOS - int zos_type; - FILE *zos_test_file; #endif /* If the file name is "-" we scan stdin */ @@ -3716,7 +3689,7 @@ directories, whereas --include and --exclude apply to everything else. The test is against the final component of the path. */ - lastcomp = strrchr(pathname, FILESEP); + char *lastcomp = strrchr(pathname, FILESEP); lastcomp = (lastcomp == NULL) ? pathname : lastcomp + 1; /* If the file is a directory, skip if not recursing or if explicitly excluded. @@ -3727,7 +3700,7 @@ /* For z/OS, determine the file type. */ #if defined NATIVE_ZOS - zos_test_file = fopen(pathname, "rb"); + FILE *zos_test_file = fopen(pathname, "rb"); if (zos_test_file == NULL) { @@ -3736,7 +3709,7 @@ return -1; } - zos_type = identifyzosfiletype(zos_test_file); + int zos_type = identifyzosfiletype(zos_test_file); fclose(zos_test_file); /* Handle a PDS in separate code */ @@ -3789,7 +3762,6 @@ while ((nextfile = readdirectory(dir)) != NULL) { - int frc; int prc; if (strlen(pathname) + strlen(nextfile) + 2 > sizeof(childpath) || (prc = snprintf(childpath, sizeof(childpath), "%s%c%s", pathname, FILESEP, nextfile)) < @@ -3813,28 +3785,25 @@ #ifdef HAVE_REALPATH { char resolvedpath[PATH_MAX]; - BOOL isSame; - size_t rlen; if (realpath(childpath, resolvedpath) == NULL) /* LCOV_EXCL_START - this is a "never" event */ continue; // This path is invalid - we can skip processing this /* LCOV_EXCL_STOP */ - isSame = strcmp(pathname, resolvedpath) == 0; + BOOL isSame = strcmp(pathname, resolvedpath) == 0; if (isSame) continue; // We have a recursion - rlen = strlen(resolvedpath); + size_t rlen = strlen(resolvedpath); if (rlen++ < sizeof(resolvedpath) - 3) { - BOOL contained; strcat(resolvedpath, "/"); - contained = strncmp(pathname, resolvedpath, rlen) == 0; + BOOL contained = strncmp(pathname, resolvedpath, rlen) == 0; if (contained) continue; // We have a recursion } } #endif /* HAVE_REALPATH */ - frc = grep_or_recurse(childpath, dir_recurse, FALSE); + int frc = grep_or_recurse(childpath, dir_recurse, FALSE); if (frc > 1) rc = frc; else if (frc == 0 && rc == 1) @@ -3864,7 +3833,6 @@ while ((nextfile = readdirectory(dir)) != NULL) { - int frc; int prc; if (strlen(pathname) + strlen(nextfile) + 1 > sizeof(buffer) || (prc = snprintf(buffer, sizeof(buffer), "%s%s", pathname, nextfile)) < 0 || @@ -3877,7 +3845,7 @@ /* LCOV_EXCL_STOP */ } - frc = grep_or_recurse(buffer, dir_recurse, FALSE); + int frc = grep_or_recurse(buffer, dir_recurse, FALSE); if (frc > 1) rc = frc; else if (frc == 0 && rc == 1) @@ -3909,7 +3877,7 @@ the file name, or the filename was forced (-H). */ #if defined SUPPORT_LIBZ || defined SUPPORT_LIBBZ2 - pathlen = (int)(strlen(pathname)); + int pathlen = (int)(strlen(pathname)); #endif /* Open using zlib if it is supported and the file name ends with .gz. */ @@ -4243,15 +4211,14 @@ static BOOL compile_pattern(patstr *p, int options, int fromfile, const char *fromtext, int count) { - char *ps; int errcode; - PCRE2_SIZE patlen, erroffset; + PCRE2_SIZE erroffset; PCRE2_UCHAR errmessbuffer[ERRBUFSIZ]; if (p->compiled != NULL) return TRUE; - ps = p->string; - patlen = p->length; + char *ps = p->string; + PCRE2_SIZE patlen = p->length; if ((options & PCRE2_LITERAL) != 0) { @@ -4425,7 +4392,6 @@ { int i, j; int rc = 1; - BOOL only_one_at_top; BOOL options_terminated = FALSE; patstr *cp; fnstr *fn; @@ -5208,7 +5174,7 @@ that there is only one argument at top level - this suppresses the file name if the argument is not a directory and filenames are not otherwise forced. */ - only_one_at_top = i == argc - 1 && file_lists == NULL; + BOOL only_one_at_top = i == argc - 1 && file_lists == NULL; for (; i < argc; i++) {
diff --git a/src/pcre2test.c b/src/pcre2test.c index 08687d5..012a64f 100644 --- a/src/pcre2test.c +++ b/src/pcre2test.c
@@ -1209,10 +1209,9 @@ cfprintf(int clr, FILE *file, const char *fmt, ...) { va_list args; - int ret; va_start(args, fmt); colour_begin(clr, file); - ret = vfprintf(file, fmt, args); + int ret = vfprintf(file, fmt, args); va_end(args); colour_end(file); return ret; @@ -1580,15 +1579,13 @@ static void * my_malloc(size_t size, void *data) { - void *block; - (void)data; mallocs_called++; if (mallocs_until_failure != INT_MAX && mallocs_until_failure-- <= 0) return NULL; - block = malloc(size); + void *block = malloc(size); if (show_memory && outfile != NULL) { if (block == NULL) @@ -1871,12 +1868,10 @@ if (c >= 0xd800 && c < 0xdc00) { - uint32_t c2; - if (utf16units >= end) return -1; - c2 = *utf16units++; + uint32_t c2 = *utf16units++; if (c2 < 0xdc00 || c2 > 0xdfff) return -1; *vptr = ((c & 0x3ff) << 10) + (c2 & 0x3ff) + 0x10000; @@ -2068,7 +2063,6 @@ { char promptbuf[80]; int snprintf_rc; - char *s; if (should_print_colour(clr_prompt, stdout)) /* libedit cannot handle ANSI escapes as the final character of a prompt, so we ensure a trailing space comes after the last escape. */ @@ -2083,7 +2077,7 @@ exit(1); } - s = readline(promptbuf); + char *s = readline(promptbuf); if (s == NULL) return (here == start) ? NULL : start; dlen = strlen(s); @@ -2693,11 +2687,10 @@ static int open_file(uint8_t *buffptr, const char *mode, FILE **fptr, const char *name) { - char *endf; char *filename = (char *)buffptr; while (isspace((unsigned char)*filename)) filename++; - endf = filename + strlen(filename); + char *endf = filename + strlen(filename); while (endf > filename && isspace((unsigned char)endf[-1])) endf--; @@ -3531,7 +3524,6 @@ { int k; int m = 0; - int16_t *fv; const ucp_type_table *t = PRIV(utt) + i; unsigned int value = t->value; @@ -3558,7 +3550,7 @@ seentypes[seencount] = t->type; seenvalues[seencount++] = t->value; - fv = found[fc++]; + int16_t *fv = found[fc++]; fv[m++] = t->name_offset; for (size_t j = i + 1; j < PRIV(utt_size); j++) @@ -3587,12 +3579,11 @@ for (int k = 0; k < (n + 1) / 2; k++) { - int x; char buff1[128]; char buff2[128]; format_list_item(found[k], buff1, wantscripts); - x = k + (n + 1) / 2; + int x = k + (n + 1) / 2; if (x < n) format_list_item(found[x], buff2, wantscripts); else @@ -3907,7 +3898,6 @@ exit(1); #else int rc = 0; - uint32_t stack_size; struct rlimit rlim, rlim_old; if (uli > INT32_MAX / (1024 * 1024)) { @@ -3915,7 +3905,7 @@ exit(1); } - stack_size = (uint32_t)uli; + uint32_t stack_size = (uint32_t)uli; getrlimit(RLIMIT_STACK, &rlim_old); rlim = rlim_old; rlim.rlim_cur = stack_size * 1024 * 1024; @@ -4213,11 +4203,9 @@ while (notdone) { - const uint8_t *p; const uint8_t *p_notsp; int rc = PR_OK; BOOL expectdata = have_active_pattern(); - BOOL is_pattern_comment; BOOL is_data_comment; #ifdef SUPPORT_PCRE2_8 expectdata |= preg.re_pcre2_code != NULL; @@ -4237,11 +4225,11 @@ /* Begin processing the line. */ - p = p_notsp = buffer; + const uint8_t *p = p_notsp = buffer; while (isspace(*p_notsp)) p_notsp++; - is_pattern_comment = p[0] == '#' && (isspace(p[1]) || p[1] == '!' || p[1] == 0); + BOOL is_pattern_comment = p[0] == '#' && (isspace(p[1]) || p[1] == '!' || p[1] == 0); is_data_comment = expectdata && p_notsp[0] == '\\' && p_notsp[1] == '=' && (isspace(p_notsp[2]) || p_notsp[2] == 0);
diff --git a/src/pcre2test_inc.h b/src/pcre2test_inc.h index 51180b0..9033f5c 100644 --- a/src/pcre2test_inc.h +++ b/src/pcre2test_inc.h
@@ -192,7 +192,6 @@ pchars(int clr, PCRE2_SPTR p, ptrdiff_t length, BOOL utf, FILE *f) { #if PCRE2_CODE_UNIT_WIDTH == 8 || PCRE2_CODE_UNIT_WIDTH == 16 - PCRE2_SPTR end; uint32_t c = 0; int yield = 0; @@ -200,7 +199,7 @@ if (length < 0) length = *p++; - end = p + length; + PCRE2_SPTR end = p + length; while (length-- > 0) { if (utf) @@ -441,7 +440,6 @@ static int to16(uint8_t *p, int utf, PCRE2_SIZE *lenptr) { - uint16_t *pp; PCRE2_SIZE len = *lenptr; if (pbuffer16_size < 2 * len + 2) @@ -460,7 +458,7 @@ } } - pp = pbuffer16; + uint16_t *pp = pbuffer16; if (!utf && (pat_patctl.control & CTL_UTF8_INPUT) == 0) { for (; len > 0; len--) @@ -543,7 +541,6 @@ static int to32(uint8_t *p, int utf, PCRE2_SIZE *lenptr) { - uint32_t *pp; PCRE2_SIZE len = *lenptr; if (pbuffer32_size < 4 * len + 4) @@ -562,7 +559,7 @@ } } - pp = pbuffer32; + uint32_t *pp = pbuffer32; if (!utf && (pat_patctl.control & CTL_UTF8_INPUT) == 0) { for (; len > 0; len--) @@ -573,7 +570,6 @@ { while (len > 0) { - int chlen; uint32_t c; uint32_t topbit = 0; const uint8_t *end = p + len; @@ -584,7 +580,7 @@ len--; } - chlen = utf8_to_ord(p, end, &c); + int chlen = utf8_to_ord(p, end, &c); if (chlen <= 0) return -1; if (utf && c > 0x10ffff) @@ -620,27 +616,22 @@ static char * config_str(uint32_t what) { - int r2; - PCRE2_UCHAR *buf; - char *buf8; - int needed_len; - - needed_len = pcre2_config(what, NULL); + int needed_len = pcre2_config(what, NULL); if (needed_len <= 0) { cfprintf(clr_test_error, stderr, "pcre2test: Error in pcre2_config(%d)\n", what); exit(1); } - buf = malloc((unsigned)needed_len * sizeof(PCRE2_UCHAR)); - buf8 = malloc((unsigned)needed_len); + PCRE2_UCHAR *buf = malloc((unsigned)needed_len * sizeof(PCRE2_UCHAR)); + char *buf8 = malloc((unsigned)needed_len); if (buf == NULL || buf8 == NULL) { cfprintf(clr_test_error, stderr, "pcre2test: malloc failed in config_str()\n"); exit(1); } - r2 = pcre2_config(what, buf); + int r2 = pcre2_config(what, buf); if (r2 != needed_len) { cfprintf(clr_test_error, stderr, "pcre2test: pcre2_config(%d) returned %d, expected %d\n", what, @@ -787,11 +778,8 @@ for (;;) { void *field; - modstruct *m; BOOL off = FALSE; unsigned int i; - size_t len; - int index; char *endptr; /* Skip white space and commas. */ @@ -825,7 +813,7 @@ pp = p; while (pp < ep && *pp != '=') pp++; - index = scan_modifiers(p, pp - p); + int index = scan_modifiers(p, pp - p); /* If the first modifier is unrecognized, try to interpret it as a sequence of single-character abbreviated modifiers. None of these modifiers have any @@ -906,7 +894,7 @@ /* We have a match on a full-name modifier. Check for the existence of data when needed. */ - m = modlist + index; // Save typing + modstruct *m = modlist + index; // Save typing if (m->type != MOD_CTL && m->type != MOD_OPT && m->type != MOD_OPTMZ && (m->type != MOD_IND || *pp == '=')) { @@ -935,7 +923,7 @@ that is to be set. If check_modifier() returns NULL, it has already output an error message. */ - len = ep - pp; + size_t len = ep - pp; field = check_modifier(m, ctx, pctl, dctl, 0); if (field == NULL) return FALSE; @@ -1115,11 +1103,10 @@ if (isdigit(*pp) || *pp == '-') { int ct = MAXCPYGET - 1; - int32_t value; li = strtol((const char *)pp, &endptr, 10); if (S32OVERFLOW(li)) goto INVALID_VALUE; - value = (int32_t)li; + int32_t value = (int32_t)li; field = (char *)field - m->offset + m->value; // Adjust field ptr if (value >= 0) // Add new number { @@ -1235,9 +1222,8 @@ static int pattern_info(int what, void *where, BOOL unsetok) { - int rc; (void)pcre2_pattern_info(compiled_code, what, NULL); // Exercise the code - rc = pcre2_pattern_info(compiled_code, what, where); + int rc = pcre2_pattern_info(compiled_code, what, where); if (rc >= 0) return 0; if (rc != PCRE2_ERROR_UNSET || !unsetok) @@ -1261,9 +1247,9 @@ show_memory_info(void) { uint32_t name_count, name_entry_size; - PCRE2_SIZE size, cblock_size, data_size; + PCRE2_SIZE size; - cblock_size = sizeof(pcre2_real_code); + PCRE2_SIZE cblock_size = sizeof(pcre2_real_code); (void)pattern_info(PCRE2_INFO_SIZE, &size, FALSE); (void)pattern_info(PCRE2_INFO_NAMECOUNT, &name_count, FALSE); @@ -1271,7 +1257,7 @@ /* The uint32_t variables are cast before multiplying to avoid potential integer overflow. */ - data_size = CU2BYTES((PCRE2_SIZE)name_count * (PCRE2_SIZE)name_entry_size); + PCRE2_SIZE data_size = CU2BYTES((PCRE2_SIZE)name_count * (PCRE2_SIZE)name_entry_size); cfprintf(clr_profiling, outfile, "Memory allocation - code size : %" SIZ_FORM "\n", size - cblock_size - data_size); @@ -1308,8 +1294,7 @@ static void show_heapframes_size(void) { - PCRE2_SIZE heapframes_size; - heapframes_size = pcre2_get_match_data_heapframes_size(match_data); + PCRE2_SIZE heapframes_size = pcre2_get_match_data_heapframes_size(match_data); cfprintf(clr_profiling, outfile, "Heapframes size in match_data: %" SIZ_FORM "\n", heapframes_size); } @@ -1324,10 +1309,9 @@ print_error_message_file(FILE *file, int errorcode, const char *before, const char *after, BOOL badcode_ok) { - int len; PCRE2_UCHAR buf[128]; - len = pcre2_get_error_message(errorcode, buf, sizeof(buf) / sizeof(*buf)); + int len = pcre2_get_error_message(errorcode, buf, sizeof(buf) / sizeof(*buf)); if (len == PCRE2_ERROR_BADDATA && badcode_ok) { cfprintf(clr_api_error, file, "%sPCRE2_ERROR_BADDATA (unknown error number)%s", before, after); @@ -1586,7 +1570,6 @@ PCRE2_SPTR nameptr_end = nameptr + pcre2_strlen(nameptr); while (*nameptr != 0) { - int len; uint8_t u8buff[6]; uint32_t c; int ord_rc = utf16_to_ord(nameptr, nameptr_end, &c); @@ -1594,7 +1577,7 @@ nameptr += ord_rc; else c = *nameptr++; - len = ord_to_utf8(c, u8buff); + int len = ord_to_utf8(c, u8buff); fprintf(outfile, "%.*s", len, u8buff); } #endif @@ -1859,16 +1842,15 @@ FILE *f; PCRE2_SIZE serial_size; size_t i; - int rc, cmd, yield, config_value; + int rc, config_value; uint16_t first_listed_newline; const char *cmdname; - size_t cmdlen; uint8_t *argptr, *serial; BOOL if_inverted; - yield = PR_OK; - cmd = CMD_UNKNOWN; - cmdlen = 0; + int yield = PR_OK; + int cmd = CMD_UNKNOWN; + size_t cmdlen = 0; for (i = 0; i < cmdlistcount; i++) { @@ -2126,8 +2108,7 @@ if (tables3 == NULL) { - int r; - r = pcre2_config(PCRE2_CONFIG_TABLES_LENGTH, &loadtables_length); + int r = pcre2_config(PCRE2_CONFIG_TABLES_LENGTH, &loadtables_length); if (r >= 0) tables3 = malloc(loadtables_length); } @@ -2167,12 +2148,11 @@ for (i = 0; i < COPTLISTCOUNT; i++) { size_t optlen = strlen(coptlist[i].name); - const uint8_t *argptr_trail; if (coptlist[i].type != CONF_FIX && coptlist[i].type != CONF_INT) continue; if (strncmp((const char *)argptr, coptlist[i].name, optlen) != 0) continue; - argptr_trail = argptr + optlen; + const uint8_t *argptr_trail = argptr + optlen; while (isspace(*argptr_trail)) argptr_trail++; if (*argptr_trail == 0 || *argptr_trail == '\n') @@ -2238,16 +2218,13 @@ static int process_pattern(void) { - BOOL utf; uint32_t k; uint8_t *p = buffer; unsigned int delimiter = *p++; int rc, errorcode; - pcre2_compile_context *use_pat_context; PCRE2_SPTR use_pbuffer; uint32_t use_forbid_utf = forbid_utf; PCRE2_SIZE patlen, full_patlen; - PCRE2_SIZE valgrind_access_length; PCRE2_SIZE erroroffset; int32_t serialize_rc; uint8_t *serialized_bytes; @@ -2312,7 +2289,7 @@ /* Note that the match_invalid_utf option also sets utf when passed to pcre2_compile(). */ - utf = (pat_patctl.options & (PCRE2_UTF | PCRE2_MATCH_INVALID_UTF)) != 0; + BOOL utf = (pat_patctl.options & (PCRE2_UTF | PCRE2_MATCH_INVALID_UTF)) != 0; /* The utf8_input modifier is not allowed in 8-bit mode, and is mutually exclusive with the utf modifier. */ @@ -2467,11 +2444,10 @@ { size_t clen = pe - pc - 2; uint32_t i = 0; - unsigned long uli; char *endptr; pe += 2; - uli = strtoul((const char *)pe, &endptr, 10); + unsigned long uli = strtoul((const char *)pe, &endptr, 10); if (U32OVERFLOW(uli)) { cfprintf(clr_test_error, outfile, "** Pattern repeat count too large\n"); @@ -2713,8 +2689,7 @@ if (rc != 0) { - char *regbuffer; - size_t bsize, usize, strsize; + size_t bsize; preg.re_pcre2_code = NULL; // In case something was left in there preg.re_match_data = NULL; @@ -2723,9 +2698,9 @@ (unsigned)pat_patctl.regerror_buffsize <= pbuffer8_size) ? (unsigned)pat_patctl.regerror_buffsize : pbuffer8_size; - regbuffer = (char *)pbuffer8 + (pbuffer8_size - bsize); - usize = regerror(rc, &preg, regbuffer, bsize); - strsize = ((usize > bsize) ? bsize : usize) - 1; + char *regbuffer = (char *)pbuffer8 + (pbuffer8_size - bsize); + size_t usize = regerror(rc, &preg, regbuffer, bsize); + size_t strsize = ((usize > bsize) ? bsize : usize) - 1; cfprintf(clr_api_error, outfile, "Failed: POSIX code %d: ", rc); if (bsize > 0) @@ -2852,7 +2827,6 @@ uint32_t convert_options = pat_patctl.convert_type; PCRE2_UCHAR *converted_pattern; PCRE2_SIZE converted_length = JUNK_OFFSET; - BOOL zero_terminate; if (pat_patctl.convert_length != CONVERT_UNSET) { @@ -2905,7 +2879,7 @@ /* Set up the input buffer in the same way as for pcre2_compile() below. */ - zero_terminate = (pat_patctl.control & (CTL_HEXPAT | CTL_USE_LENGTH)) == 0; + BOOL zero_terminate = (pat_patctl.control & (CTL_HEXPAT | CTL_USE_LENGTH)) == 0; #ifdef SUPPORT_VALGRIND VALGRIND_MAKE_MEM_NOACCESS(pbuffer + CU2BYTES(patlen + zero_terminate), @@ -2972,7 +2946,7 @@ to be marked as no-access. */ full_patlen = patlen; - valgrind_access_length = patlen; + PCRE2_SIZE valgrind_access_length = patlen; if ((pat_patctl.control & (CTL_HEXPAT | CTL_USE_LENGTH)) == 0) { patlen = PCRE2_ZERO_TERMINATED; @@ -2998,7 +2972,8 @@ /* The null_context modifier is used to test calling pcre2_compile() with a NULL context. */ - use_pat_context = ((pat_patctl.control & CTL_NULLCONTEXT) != 0) ? NULL : pat_context; + pcre2_compile_context *use_pat_context = + ((pat_patctl.control & CTL_NULLCONTEXT) != 0) ? NULL : pat_context; /* If PCRE2_LITERAL is set, set use_forbid_utf zero because PCRE2_NEVER_UTF and PCRE2_NEVER_UCP are invalid with it. */ @@ -3899,18 +3874,16 @@ copy_and_get(BOOL utf, int capcount) { int i; - uint8_t *nptr; /* Test copy strings by number */ for (i = 0; i < MAXCPYGET && dat_datctl.copy_numbers[i] >= 0; i++) { - int rc, rc2; - PCRE2_SIZE length, length2; + PCRE2_SIZE length2; PCRE2_UCHAR copybuffer[256]; uint32_t n = (uint32_t)(dat_datctl.copy_numbers[i]); - length = sizeof(copybuffer) / sizeof(*copybuffer); - rc = pcre2_substring_copy_bynumber(match_data, n, copybuffer, &length); + PCRE2_SIZE length = sizeof(copybuffer) / sizeof(*copybuffer); + int rc = pcre2_substring_copy_bynumber(match_data, n, copybuffer, &length); if (rc < 0) { cfprintf(clr_api_error, outfile, "Copy substring %d failed (%d): ", n, rc); @@ -3924,7 +3897,7 @@ fprintf(outfile, " (%" SIZ_FORM ")\n", length); } - rc2 = pcre2_substring_length_bynumber(match_data, n, &length2); + int rc2 = pcre2_substring_length_bynumber(match_data, n, &length2); if (rc2 < 0) { cfprintf(clr_api_error, outfile, "Get substring %d length failed (%d): ", n, rc2); @@ -3940,12 +3913,10 @@ /* Test copy strings by name */ - nptr = dat_datctl.copy_names; + uint8_t *nptr = dat_datctl.copy_names; for (;;) { - int rc, rc2; - int groupnumber; - PCRE2_SIZE length, length2; + PCRE2_SIZE length2; PCRE2_UCHAR copybuffer[256]; size_t namelen = strlen((const char *)nptr); #if PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 @@ -3967,12 +3938,12 @@ (void)to32(nptr, utf, &cnl); #endif - groupnumber = pcre2_substring_number_from_name(compiled_code, pbuffer); + int groupnumber = pcre2_substring_number_from_name(compiled_code, pbuffer); if (groupnumber < 0 && groupnumber != PCRE2_ERROR_NOUNIQUESUBSTRING) cfprintf(clr_api_error, outfile, "Number not found for group \"%s\"\n", nptr); - length = sizeof(copybuffer) / sizeof(*copybuffer); - rc = pcre2_substring_copy_byname(match_data, pbuffer, copybuffer, &length); + PCRE2_SIZE length = sizeof(copybuffer) / sizeof(*copybuffer); + int rc = pcre2_substring_copy_byname(match_data, pbuffer, copybuffer, &length); if (rc < 0) { cfprintf(clr_api_error, outfile, "Copy substring \"%s\" failed (%d): ", nptr, rc); @@ -3990,7 +3961,7 @@ fprintf(outfile, " (non-unique)\n"); } - rc2 = pcre2_substring_length_byname(match_data, pbuffer, &length2); + int rc2 = pcre2_substring_length_byname(match_data, pbuffer, &length2); if (rc2 < 0) { cfprintf(clr_api_error, outfile, "Get substring \"%s\" length failed (%d): ", nptr, rc2); @@ -4010,11 +3981,10 @@ for (i = 0; i < MAXCPYGET && dat_datctl.get_numbers[i] >= 0; i++) { - int rc; PCRE2_SIZE length; PCRE2_UCHAR *gotbuffer; uint32_t n = (uint32_t)(dat_datctl.get_numbers[i]); - rc = pcre2_substring_get_bynumber(match_data, n, &gotbuffer, &length); + int rc = pcre2_substring_get_bynumber(match_data, n, &gotbuffer, &length); if (rc < 0) { cfprintf(clr_api_error, outfile, "Get substring %d failed (%d): ", n, rc); @@ -4037,8 +4007,6 @@ { PCRE2_SIZE length; PCRE2_UCHAR *gotbuffer; - int rc; - int groupnumber; size_t namelen = strlen((const char *)nptr); #if PCRE2_CODE_UNIT_WIDTH == 16 || PCRE2_CODE_UNIT_WIDTH == 32 PCRE2_SIZE cnl = namelen; @@ -4059,11 +4027,11 @@ (void)to32(nptr, utf, &cnl); #endif - groupnumber = pcre2_substring_number_from_name(compiled_code, pbuffer); + int groupnumber = pcre2_substring_number_from_name(compiled_code, pbuffer); if (groupnumber < 0 && groupnumber != PCRE2_ERROR_NOUNIQUESUBSTRING) cfprintf(clr_api_error, outfile, "Number not found for group \"%s\"\n", nptr); - rc = pcre2_substring_get_byname(match_data, pbuffer, &gotbuffer, &length); + int rc = pcre2_substring_get_byname(match_data, pbuffer, &gotbuffer, &length); if (rc < 0) { cfprintf(clr_api_error, outfile, "Get substring \"%s\" failed (%d): ", nptr, rc); @@ -4089,10 +4057,9 @@ if ((dat_datctl.control & CTL_GETALL) != 0) { - int rc; PCRE2_UCHAR **stringlist; PCRE2_SIZE *lengths; - rc = pcre2_substring_list_get(match_data, &stringlist, &lengths); + int rc = pcre2_substring_list_get(match_data, &stringlist, &lengths); if (rc < 0) { cfprintf(clr_api_error, outfile, "get substring list failed (%d): ", rc); @@ -4219,22 +4186,17 @@ uint32_t gmatched; uint32_t c, k; uint32_t g_notempty = 0; - uint8_t *p; // Position within buffer (raw input line) - size_t len; - size_t needlen; // Bytes, for sizing dbuffer pcre2_match_context *use_dat_context; BOOL utf; - BOOL subject_literal; PCRE2_SIZE *ovector; PCRE2_SPTR ovecsave[2] = { NULL, NULL }; uint32_t oveccount; PCRE2_UCHAR *q = NULL; // Typed pointer within dbuffer - PCRE2_UCHAR *start_rep; // Position within dbuffer; stashed value of q PCRE2_UCHAR *pp; // Subject pointer within dbuffer - subject_literal = (pat_patctl.control2 & CTL2_SUBJECT_LITERAL) != 0; + BOOL subject_literal = (pat_patctl.control2 & CTL2_SUBJECT_LITERAL) != 0; /* Copy the default context and data control blocks to the active ones. Then copy from the pattern the controls that can be set in either the pattern or the @@ -4268,12 +4230,12 @@ utf = (compiled_code->overall_options & PCRE2_UTF) != 0; #endif - start_rep = NULL; - len = strlen((const char *)buffer); + PCRE2_UCHAR *start_rep = NULL; // Position within dbuffer; stashed value of q + size_t len = strlen((const char *)buffer); while (len > 0 && isspace(buffer[len - 1])) len--; buffer[len] = 0; - p = buffer; + uint8_t *p = buffer; // Position within buffer (raw input line) while (isspace(*p)) { p++; @@ -4313,7 +4275,7 @@ the number of code units that will be needed (though the buffer may have to be extended if replication is involved). */ - needlen = CU2BYTES(len + 1); + size_t needlen = CU2BYTES(len + 1); // Bytes, for sizing dbuffer if (dbuffer == NULL || needlen >= dbuffer_size) { while (needlen >= dbuffer_size) @@ -4349,7 +4311,6 @@ if (c == ']' && start_rep != NULL) { - long li; char *endptr; if (*p++ != '{') @@ -4358,7 +4319,7 @@ return PR_OK; } - li = strtol((const char *)p, &endptr, 10); + long li = strtol((const char *)p, &endptr, 10); if (S32OVERFLOW(li)) { cfprintf(clr_test_error, outfile, "** Repeat count too large\n"); @@ -4601,11 +4562,10 @@ if (memcmp(p, "{U+", 3) == 0 && isxdigit(p[3])) { char *endptr; - unsigned long uli; p += 3; errno = 0; - uli = strtoul((const char *)p, &endptr, 16); + unsigned long uli = strtoul((const char *)p, &endptr, 16); if (errno == 0 && *endptr == '}' && uli <= UINT32_MAX) { c = (uint32_t)uli; @@ -4855,7 +4815,6 @@ #if PCRE2_CODE_UNIT_WIDTH == 8 if ((pat_patctl.control & CTL_POSIX) != 0) { - int rc; int eflags = 0; regmatch_t *pmatch = NULL; regmatch_t startend_buf; @@ -4922,7 +4881,7 @@ if ((dat_datctl.options & PCRE2_NOTEMPTY) != 0) eflags |= REG_NOTEMPTY; - rc = regexec(&preg, (const char *)pp, dat_datctl.oveccount, pmatch, eflags); + int rc = regexec(&preg, (const char *)pp, dat_datctl.oveccount, pmatch, eflags); if (rc != 0) { size_t usize = regerror(rc, &preg, (char *)pbuffer8, pbuffer8_size); @@ -5129,9 +5088,6 @@ int rc; uint8_t *pr, *prend; PCRE2_UCHAR sbuffer[SUBSTITUTE_SUBJECT_MODSIZE]; // Staging, not seen by pcre2_substitute() - PCRE2_UCHAR *obptr; - PCRE2_UCHAR *rbptr; - PCRE2_UCHAR *sbptr; uint32_t xoptions; uint32_t emoption; // External match option PCRE2_SIZE j, rlen, full_rlen, nsize, nsize_input, slen; @@ -5248,13 +5204,15 @@ full_rlen = rlen; if ((dat_datctl.control & CTL_ZERO_TERMINATE) != 0) rlen = PCRE2_ZERO_TERMINATED; - obptr = ((dat_datctl.control2 & CTL2_NULL_SUBSTITUTE_BUFFER) == 0) ? rep_out_buffer : NULL; - rbptr = ((dat_datctl.control2 & CTL2_NULL_REPLACEMENT) == 0) ? rep_in_buffer : NULL; + PCRE2_UCHAR *obptr = + ((dat_datctl.control2 & CTL2_NULL_SUBSTITUTE_BUFFER) == 0) ? rep_out_buffer : NULL; + PCRE2_UCHAR *rbptr = + ((dat_datctl.control2 & CTL2_NULL_REPLACEMENT) == 0) ? rep_in_buffer : NULL; /* If the substitute_subject modifier is set, then we will modify the subject in between the call to pcre2_match and pcre2_substitute. */ - sbptr = pp; + PCRE2_UCHAR *sbptr = pp; slen = arg_ulen; if (dat_datctl.substitute_subject[0] != MOD_STR_UNSET) @@ -5585,10 +5543,9 @@ if (match_rc < 0 && (dat_datctl.control & CTL_ANYGLOB) != 0) { - BOOL rc_nextmatch; PCRE2_SIZE tmp_offset = 0xcd; uint32_t tmp_options = 0xcd; - rc_nextmatch = pcre2_next_match(match_data, &tmp_offset, &tmp_options); + BOOL rc_nextmatch = pcre2_next_match(match_data, &tmp_offset, &tmp_options); if (rc_nextmatch || tmp_offset != 0xcd || tmp_options != 0xcd) { cfprintf(clr_test_error, outfile, "** unexpected pcre2_next_match() for rc < 0\n"); @@ -5604,9 +5561,6 @@ if (match_rc >= 0) { - int capcount_rc; /* Number of capture pairs held in the ovector */ - int capcount_display; /* Number of capture pairs to display */ - if (pp == NULL) { #ifdef SUPPORT_VALGRIND @@ -5621,7 +5575,8 @@ pair in it has been set. Keep the raw return code separate from the number of pairs held. */ - capcount_rc = (match_rc == 0) ? (int)oveccount : match_rc; + /* Number of capture pairs held in the ovector. */ + int capcount_rc = (match_rc == 0) ? (int)oveccount : match_rc; if ((unsigned)capcount_rc > oveccount) // Check for lunatic return value { @@ -5711,7 +5666,7 @@ by setting capcount_display to the maximum. This is not relevant for DFA matching, so ignore it (warning given above). */ - capcount_display = capcount_rc; + int capcount_display = capcount_rc; /* Number of capture pairs to display */ if ((dat_datctl.control & (CTL_ALLCAPTURES | CTL_DFA)) == CTL_ALLCAPTURES) { @@ -5815,8 +5770,7 @@ else if ((dat_datctl.control & CTL_STARTCHAR) != 0) { - PCRE2_SIZE startchar; - startchar = pcre2_get_startchar(match_data); + PCRE2_SIZE startchar = pcre2_get_startchar(match_data); lleft = pchars(clr_none, pp + startchar, start - startchar, utf, outfile); pchars(clr_none, pp + start, end - start, utf, outfile); if ((pat_patctl.control & CTL_JITVERIFY) != 0 && jit_was_used) @@ -5884,7 +5838,6 @@ else if (match_rc == PCRE2_ERROR_PARTIAL) { PCRE2_SIZE leftchar; - int backlength; int rubriclength = 0; if ((dat_datctl.control & CTL_ALLUSEDTEXT) != 0) @@ -5907,7 +5860,7 @@ fprintf(outfile, ": "); rubriclength += 15; - backlength = pchars(clr_input, pp + leftchar, ovector[0] - leftchar, utf, outfile); + int backlength = pchars(clr_input, pp + leftchar, ovector[0] - leftchar, utf, outfile); pchars(clr_input, pp + ovector[0], ovector[1] - ovector[0], utf, outfile); if ((pat_patctl.control & CTL_JITVERIFY) != 0 && jit_was_used) @@ -5982,8 +5935,7 @@ return PR_ABEND; if (match_rc <= PCRE2_ERROR_UTF8_ERR1 && match_rc >= PCRE2_ERROR_UTF32_ERR2) { - PCRE2_SIZE startchar; - startchar = pcre2_get_startchar(match_data); + PCRE2_SIZE startchar = pcre2_get_startchar(match_data); cfprintf(clr_api_error, outfile, " at offset %" SIZ_FORM, startchar); } @@ -6007,14 +5959,13 @@ else { PCRE2_SIZE new_start_offset = (PCRE2_SIZE)-1; - BOOL rc_nextmatch; /* Use pcre2_next_match() to safely advance. This guarantees that the start offset will advance, except after an empty match, in which case it sets the PCRE2_NOTEMPTY_ATSTART flag to ensure the next match does not return a duplicate. */ - rc_nextmatch = pcre2_next_match(match_data, &new_start_offset, &g_notempty); + BOOL rc_nextmatch = pcre2_next_match(match_data, &new_start_offset, &g_notempty); if (!rc_nextmatch) break; // Out of the /g loop @@ -6146,11 +6097,8 @@ static void unittest(void) { - int rc; - uint32_t uval; - PCRE2_SIZE sizeval; - PCRE2_UCHAR *sptrval; const char *failure = NULL; + uint32_t uval; pcre2_general_context *test_gen_context = NULL, *test_gen_context_copy = NULL; pcre2_compile_context *test_pat_context = NULL, *test_pat_context_copy = NULL; pcre2_match_context *test_dat_context = NULL, *test_dat_context_copy = NULL; @@ -6228,7 +6176,7 @@ /* -------------------------- pcre2_config --------------------------------- */ - rc = pcre2_config(PCRE2_CONFIG_BSR, NULL); + int rc = pcre2_config(PCRE2_CONFIG_BSR, NULL); ASSERT(rc == (int)sizeof(uint32_t), "pcre2_config(NULL)"); rc = pcre2_config(PCRE2_CONFIG_COMPILED_WIDTHS, NULL); ASSERT(rc == (int)sizeof(uint32_t), "pcre2_config(NULL)"); @@ -6389,7 +6337,7 @@ ASSERT(rc == 0, "pcre2_get_bsr()"); ASSERT(uval == BSR_DEFAULT, "pcre2_get_bsr()"); - sizeval = 123; + PCRE2_SIZE sizeval = 123; rc = pcre2_get_max_pattern_length(test_pat_context, &sizeval); ASSERT(rc == 0, "pcre2_get_max_pattern_length()"); ASSERT(sizeval == PCRE2_UNSET, "pcre2_get_max_pattern_length()"); @@ -7039,7 +6987,7 @@ /* Test before any match has been attempted. */ sizeval = 4; - sptrval = NULL; + PCRE2_UCHAR *sptrval = NULL; stringlist = NULL; lengthslist = NULL; rc = pcre2_substring_copy_byname(test_match_data, name_n, copy_buf, &sizeval);