Fix some picky compiler warnings

This commit is contained in:
Philip.Hazel 2016-02-16 10:23:06 +00:00
parent 88027b4625
commit c28ed7fd4a
7 changed files with 209 additions and 190 deletions

View File

@ -65,6 +65,10 @@ compiling workspace (which was diagnosed, but of course is not desirable).
13. Detect missing closing parentheses during the pre-pass for group 13. Detect missing closing parentheses during the pre-pass for group
identification. identification.
14. Changed some integer variable types and put in a number of casts, following
a report of compiler warnings from Visual Studio 2013 and a few tests with
gcc's -Wconversion (which still throws up a lot).
Version 10.21 12-January-2016 Version 10.21 12-January-2016
----------------------------- -----------------------------

View File

@ -81,7 +81,7 @@ by defining macros in order to minimize #if usage. */
/* Function definitions to allow mutual recursion */ /* Function definitions to allow mutual recursion */
static int static unsigned int
add_list_to_class(uint8_t *, PCRE2_UCHAR **, uint32_t, compile_block *, add_list_to_class(uint8_t *, PCRE2_UCHAR **, uint32_t, compile_block *,
const uint32_t *, unsigned int); const uint32_t *, unsigned int);
@ -149,9 +149,16 @@ have to check them every time. */
#define OFLOW_MAX (INT_MAX - 20) #define OFLOW_MAX (INT_MAX - 20)
/* Macro for setting individual bits in class bitmaps. */ /* Macro for setting individual bits in class bitmaps. It took some
experimenting to figure out how to stop gcc 5.3.0 from warning with
-Wconversion. This version gets a warning:
#define SETBIT(a,b) a[(b)/8] |= (1 << ((b)&7)) #define SETBIT(a,b) a[(b)/8] |= (uint8_t)(1 << ((b)&7))
Let's hope the apparently less efficient version isn't actually so bad if the
compiler is clever with identical subexpressions. */
#define SETBIT(a,b) a[(b)/8] = (uint8_t)(a[(b)/8] | (1 << ((b)&7)))
/* Private flags added to firstcu and reqcu. */ /* Private flags added to firstcu and reqcu. */
@ -804,7 +811,7 @@ static void
complete_callout(PCRE2_UCHAR *previous_callout, PCRE2_SPTR ptr, complete_callout(PCRE2_UCHAR *previous_callout, PCRE2_SPTR ptr,
compile_block *cb) compile_block *cb)
{ {
size_t length = ptr - cb->start_pattern - GET(previous_callout, 1); size_t length = (size_t)(ptr - cb->start_pattern - GET(previous_callout, 1));
PUT(previous_callout, 1 + LINK_SIZE, length); PUT(previous_callout, 1 + LINK_SIZE, length);
} }
@ -855,11 +862,11 @@ static int
find_fixedlength(PCRE2_UCHAR *code, BOOL utf, BOOL atend, compile_block *cb, find_fixedlength(PCRE2_UCHAR *code, BOOL utf, BOOL atend, compile_block *cb,
recurse_check *recurses, int *countptr) recurse_check *recurses, int *countptr)
{ {
int length = -1; uint32_t length = 0xffffffffu; /* Unset */
uint32_t group = 0; uint32_t group = 0;
uint32_t groupinfo = 0; uint32_t groupinfo = 0;
recurse_check this_recurse; recurse_check this_recurse;
register int branchlength = 0; register uint32_t branchlength = 0;
register PCRE2_UCHAR *cc = code + 1 + LINK_SIZE; register PCRE2_UCHAR *cc = code + 1 + LINK_SIZE;
/* If this is a capturing group, we may have the answer cached, but we can only /* If this is a capturing group, we may have the answer cached, but we can only
@ -910,7 +917,7 @@ for (;;)
case OP_COND: case OP_COND:
d = find_fixedlength(cc, utf, atend, cb, recurses, countptr); d = find_fixedlength(cc, utf, atend, cb, recurses, countptr);
if (d < 0) return d; if (d < 0) return d;
branchlength += d; branchlength += (uint32_t)d;
do cc += GET(cc, 1); while (*cc == OP_ALT); do cc += GET(cc, 1); while (*cc == OP_ALT);
cc += 1 + LINK_SIZE; cc += 1 + LINK_SIZE;
break; break;
@ -926,16 +933,16 @@ for (;;)
case OP_END: case OP_END:
case OP_ACCEPT: case OP_ACCEPT:
case OP_ASSERT_ACCEPT: case OP_ASSERT_ACCEPT:
if (length < 0) length = branchlength; if (length == 0xffffffffu) length = branchlength;
else if (length != branchlength) goto ISNOTFIXED; else if (length != branchlength) goto ISNOTFIXED;
if (*cc != OP_ALT) if (*cc != OP_ALT)
{ {
if (group > 0) if (group > 0)
{ {
groupinfo |= (GI_SET_FIXED_LENGTH | length); groupinfo |= (uint32_t)(GI_SET_FIXED_LENGTH | length);
cb->groupinfo[group] = groupinfo; cb->groupinfo[group] = groupinfo;
} }
return length; return (int)length;
} }
cc += 1 + LINK_SIZE; cc += 1 + LINK_SIZE;
branchlength = 0; branchlength = 0;
@ -960,7 +967,7 @@ for (;;)
this_recurse.group = cs; this_recurse.group = cs;
d = find_fixedlength(cs, utf, atend, cb, &this_recurse, countptr); d = find_fixedlength(cs, utf, atend, cb, &this_recurse, countptr);
if (d < 0) return d; if (d < 0) return d;
branchlength += d; branchlength += (uint32_t)d;
cc += 1 + LINK_SIZE; cc += 1 + LINK_SIZE;
break; break;
@ -1039,7 +1046,7 @@ for (;;)
case OP_EXACTI: case OP_EXACTI:
case OP_NOTEXACT: case OP_NOTEXACT:
case OP_NOTEXACTI: case OP_NOTEXACTI:
branchlength += (int)GET2(cc,1); branchlength += GET2(cc,1);
cc += 2 + IMM2_SIZE; cc += 2 + IMM2_SIZE;
#ifdef SUPPORT_UNICODE #ifdef SUPPORT_UNICODE
if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]); if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
@ -1115,7 +1122,7 @@ for (;;)
case OP_CRMINRANGE: case OP_CRMINRANGE:
case OP_CRPOSRANGE: case OP_CRPOSRANGE:
if (GET2(cc,1) != GET2(cc,1+IMM2_SIZE)) goto ISNOTFIXED; if (GET2(cc,1) != GET2(cc,1+IMM2_SIZE)) goto ISNOTFIXED;
branchlength += (int)GET2(cc,1); branchlength += GET2(cc,1);
cc += 1 + 2 * IMM2_SIZE; cc += 1 + 2 * IMM2_SIZE;
break; break;
@ -1941,7 +1948,7 @@ else
overflow = TRUE; overflow = TRUE;
break; break;
} }
s = s * 10 + (int)(*(++ptr) - CHAR_0); s = s * 10 + (unsigned int)(*(++ptr) - CHAR_0);
} }
if (overflow) /* Integer overflow */ if (overflow) /* Integer overflow */
{ {
@ -2005,7 +2012,7 @@ else
overflow = TRUE; overflow = TRUE;
break; break;
} }
s = s * 10 + (int)(*(++ptr) - CHAR_0); s = s * 10 + (unsigned int)(*(++ptr) - CHAR_0);
} }
if (overflow) /* Integer overflow */ if (overflow) /* Integer overflow */
{ {
@ -2285,7 +2292,7 @@ get_ucp(PCRE2_SPTR *ptrptr, BOOL *negptr, unsigned int *ptypeptr,
unsigned int *pdataptr, int *errorcodeptr, compile_block *cb) unsigned int *pdataptr, int *errorcodeptr, compile_block *cb)
{ {
register PCRE2_UCHAR c; register PCRE2_UCHAR c;
int i, bot, top; size_t i, bot, top;
PCRE2_SPTR ptr = *ptrptr; PCRE2_SPTR ptr = *ptrptr;
PCRE2_UCHAR name[32]; PCRE2_UCHAR name[32];
@ -2753,13 +2760,13 @@ Returns: the number of < 256 characters added
the pointer to extra data is updated the pointer to extra data is updated
*/ */
static int static unsigned int
add_to_class(uint8_t *classbits, PCRE2_UCHAR **uchardptr, uint32_t options, add_to_class(uint8_t *classbits, PCRE2_UCHAR **uchardptr, uint32_t options,
compile_block *cb, uint32_t start, uint32_t end) compile_block *cb, uint32_t start, uint32_t end)
{ {
uint32_t c; uint32_t c;
uint32_t classbits_end = (end <= 0xff ? end : 0xff); uint32_t classbits_end = (end <= 0xff ? end : 0xff);
int n8 = 0; unsigned int n8 = 0;
/* If caseless matching is required, scan the range and process alternate /* If caseless matching is required, scan the range and process alternate
cases. In Unicode, there are 8-bit characters that have alternate cases that cases. In Unicode, there are 8-bit characters that have alternate cases that
@ -2907,14 +2914,14 @@ Returns: the number of < 256 characters added
the pointer to extra data is updated the pointer to extra data is updated
*/ */
static int static unsigned int
add_list_to_class(uint8_t *classbits, PCRE2_UCHAR **uchardptr, uint32_t options, add_list_to_class(uint8_t *classbits, PCRE2_UCHAR **uchardptr, uint32_t options,
compile_block *cb, const uint32_t *p, unsigned int except) compile_block *cb, const uint32_t *p, unsigned int except)
{ {
int n8 = 0; unsigned int n8 = 0;
while (p[0] < NOTACHAR) while (p[0] < NOTACHAR)
{ {
int n = 0; unsigned int n = 0;
if (p[0] != except) if (p[0] != except)
{ {
while(p[n+1] == p[0] + n + 1) n++; while(p[n+1] == p[0] + n + 1) n++;
@ -2945,12 +2952,12 @@ Returns: the number of < 256 characters added
the pointer to extra data is updated the pointer to extra data is updated
*/ */
static int static unsigned int
add_not_list_to_class(uint8_t *classbits, PCRE2_UCHAR **uchardptr, add_not_list_to_class(uint8_t *classbits, PCRE2_UCHAR **uchardptr,
uint32_t options, compile_block *cb, const uint32_t *p) uint32_t options, compile_block *cb, const uint32_t *p)
{ {
BOOL utf = (options & PCRE2_UTF) != 0; BOOL utf = (options & PCRE2_UTF) != 0;
int n8 = 0; unsigned int n8 = 0;
if (p[0] > 0) if (p[0] > 0)
n8 += add_to_class(classbits, uchardptr, options, cb, 0, p[0] - 1); n8 += add_to_class(classbits, uchardptr, options, cb, 0, p[0] - 1);
while (p[0] < NOTACHAR) while (p[0] < NOTACHAR)
@ -3099,7 +3106,7 @@ for (; ptr < cb->end_pattern; ptr++)
/* Not UTF */ /* Not UTF */
{ {
if (code != NULL) *code++ = x; if (code != NULL) *code++ = (PCRE2_UCHAR)x;
} }
arglen++; arglen++;
@ -3173,14 +3180,14 @@ typedef struct nest_save {
#define NSF_EXTENDED 0x0002u #define NSF_EXTENDED 0x0002u
#define NSF_DUPNAMES 0x0004u #define NSF_DUPNAMES 0x0004u
static uint32_t scan_for_captures(PCRE2_SPTR *ptrptr, uint32_t options, static int scan_for_captures(PCRE2_SPTR *ptrptr, uint32_t options,
compile_block *cb) compile_block *cb)
{ {
uint32_t c; uint32_t c;
uint32_t delimiter; uint32_t delimiter;
uint32_t nest_depth = 0;
uint32_t set, unset, *optset; uint32_t set, unset, *optset;
uint32_t skiptoket = 0; uint32_t skiptoket = 0;
uint16_t nest_depth = 0;
int errorcode = 0; int errorcode = 0;
int escape; int escape;
int namelen; int namelen;
@ -3438,8 +3445,8 @@ for (; ptr < cb->end_pattern; ptr++)
if (*ptr == CHAR_VERTICAL_LINE) if (*ptr == CHAR_VERTICAL_LINE)
{ {
top_nest->reset_group = cb->bracount; top_nest->reset_group = (uint16_t)cb->bracount;
top_nest->max_group = cb->bracount; top_nest->max_group = (uint16_t)cb->bracount;
top_nest->flags |= NSF_RESET; top_nest->flags |= NSF_RESET;
cb->external_flags |= PCRE2_DUPCAPUSED; cb->external_flags |= PCRE2_DUPCAPUSED;
break; break;
@ -3474,9 +3481,10 @@ for (; ptr < cb->end_pattern; ptr++)
case CHAR_U: case CHAR_U:
break; break;
default: errorcode = ERR11; default:
ptr--; /* Correct the offset */ errorcode = ERR11;
goto FAILED; ptr--; /* Correct the offset */
goto FAILED;
} }
} }
@ -3652,7 +3660,7 @@ for (; ptr < cb->end_pattern; ptr++)
} }
if (namelen + IMM2_SIZE + 1 > cb->name_entry_size) if (namelen + IMM2_SIZE + 1 > cb->name_entry_size)
cb->name_entry_size = namelen + IMM2_SIZE + 1; cb->name_entry_size = (uint16_t)(namelen + IMM2_SIZE + 1);
/* We have a valid name for this capturing group. */ /* We have a valid name for this capturing group. */
@ -3670,7 +3678,7 @@ for (; ptr < cb->end_pattern; ptr++)
for (i = 0; i < cb->names_found; i++, ng++) for (i = 0; i < cb->names_found; i++, ng++)
{ {
if (namelen == ng->length && if (namelen == ng->length &&
PRIV(strncmp)(name, ng->name, namelen) == 0) PRIV(strncmp)(name, ng->name, (size_t)namelen) == 0)
{ {
if (ng->number == cb->bracount) break; if (ng->number == cb->bracount) break;
if ((options & PCRE2_DUPNAMES) == 0) if ((options & PCRE2_DUPNAMES) == 0)
@ -3694,7 +3702,7 @@ for (; ptr < cb->end_pattern; ptr++)
if (cb->names_found >= cb->named_group_list_size) if (cb->names_found >= cb->named_group_list_size)
{ {
int newsize = cb->named_group_list_size * 2; uint32_t newsize = cb->named_group_list_size * 2;
named_group *newspace = named_group *newspace =
cb->cx->memctl.malloc(newsize * sizeof(named_group), cb->cx->memctl.malloc(newsize * sizeof(named_group),
cb->cx->memctl.memory_data); cb->cx->memctl.memory_data);
@ -3716,9 +3724,9 @@ for (; ptr < cb->end_pattern; ptr++)
/* Add this name to the list */ /* Add this name to the list */
cb->named_groups[cb->names_found].name = name; cb->named_groups[cb->names_found].name = name;
cb->named_groups[cb->names_found].length = namelen; cb->named_groups[cb->names_found].length = (uint16_t)namelen;
cb->named_groups[cb->names_found].number = cb->bracount; cb->named_groups[cb->names_found].number = cb->bracount;
cb->named_groups[cb->names_found].isdup = isdupname; cb->named_groups[cb->names_found].isdup = (uint16_t)isdupname;
cb->names_found++; cb->names_found++;
break; break;
} /* End of (? switch */ } /* End of (? switch */
@ -3731,7 +3739,7 @@ for (; ptr < cb->end_pattern; ptr++)
(top_nest->flags & NSF_RESET) != 0) (top_nest->flags & NSF_RESET) != 0)
{ {
if (cb->bracount > top_nest->max_group) if (cb->bracount > top_nest->max_group)
top_nest->max_group = cb->bracount; top_nest->max_group = (uint16_t)cb->bracount;
cb->bracount = top_nest->reset_group; cb->bracount = top_nest->reset_group;
} }
break; break;
@ -3966,7 +3974,7 @@ for (;; ptr++)
*errorcodeptr = ERR20; *errorcodeptr = ERR20;
goto FAILED; goto FAILED;
} }
*lengthptr += code - last_code; *lengthptr += (size_t)(code - last_code);
/* If "previous" is set and it is not at the start of the work space, move /* If "previous" is set and it is not at the start of the work space, move
it back to there, in order to avoid filling up the work space. Otherwise, it back to there, in order to avoid filling up the work space. Otherwise,
@ -3976,7 +3984,7 @@ for (;; ptr++)
{ {
if (previous > orig_code) if (previous > orig_code)
{ {
memmove(orig_code, previous, CU2BYTES(code - previous)); memmove(orig_code, previous, (size_t)CU2BYTES(code - previous));
code -= previous - orig_code; code -= previous - orig_code;
previous = orig_code; previous = orig_code;
} }
@ -4137,7 +4145,7 @@ for (;; ptr++)
*errorcodeptr = ERR20; *errorcodeptr = ERR20;
goto FAILED; goto FAILED;
} }
*lengthptr += code - last_code; /* To include callout length */ *lengthptr += (size_t)(code - last_code); /* To include callout length */
} }
return TRUE; return TRUE;
@ -4425,7 +4433,7 @@ for (;; ptr++)
case PC_PUNCT: case PC_PUNCT:
if (ptype == 0) ptype = PT_PXPUNCT; if (ptype == 0) ptype = PT_PXPUNCT;
*class_uchardata++ = local_negate? XCL_NOTPROP : XCL_PROP; *class_uchardata++ = local_negate? XCL_NOTPROP : XCL_PROP;
*class_uchardata++ = ptype; *class_uchardata++ = (PCRE2_UCHAR)ptype;
*class_uchardata++ = 0; *class_uchardata++ = 0;
xclass_has_prop = TRUE; xclass_has_prop = TRUE;
ptr = tempptr + 1; ptr = tempptr + 1;
@ -4473,9 +4481,9 @@ for (;; ptr++)
if (taboffset >= 0) if (taboffset >= 0)
{ {
if (tabopt >= 0) if (tabopt >= 0)
for (c = 0; c < 32; c++) pbits[c] |= cbits[c + taboffset]; for (c = 0; c < 32; c++) pbits[c] |= cbits[(int)c + taboffset];
else else
for (c = 0; c < 32; c++) pbits[c] &= ~cbits[c + taboffset]; for (c = 0; c < 32; c++) pbits[c] &= ~cbits[(int)c + taboffset];
} }
/* Now see if we need to remove any special characters. An option /* Now see if we need to remove any special characters. An option

View File

@ -61,15 +61,16 @@ convenient for user programs that want to test their values. */
* Return info about what features are configured * * Return info about what features are configured *
*************************************************/ *************************************************/
/* /* If where is NULL, the length of memory required is returned.
Arguments: Arguments:
what what information is required what what information is required
where where to put the information where where to put the information
Returns: 0 if data returned Returns: 0 if a numerical value is returned
>= 0 if where is NULL, giving length required >= 0 if a string value
PCRE2_ERROR_BADOPTION if "where" not recognized PCRE2_ERROR_BADOPTION if "where" not recognized
or JIT target requested when JIT not enabled or JIT target requested when JIT not enabled
*/ */
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
@ -127,15 +128,15 @@ switch (what)
#ifdef SUPPORT_JIT #ifdef SUPPORT_JIT
{ {
const char *v = PRIV(jit_get_target)(); const char *v = PRIV(jit_get_target)();
return 1 + ((where == NULL)? return (int)(1 + ((where == NULL)?
strlen(v) : PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v)); strlen(v) : PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v)));
} }
#else #else
return PCRE2_ERROR_BADOPTION; return PCRE2_ERROR_BADOPTION;
#endif #endif
case PCRE2_CONFIG_LINKSIZE: case PCRE2_CONFIG_LINKSIZE:
*((uint32_t *)where) = configured_link_size; *((uint32_t *)where) = (uint32_t)configured_link_size;
break; break;
case PCRE2_CONFIG_MATCHLIMIT: case PCRE2_CONFIG_MATCHLIMIT:
@ -169,8 +170,8 @@ switch (what)
#else #else
const char *v = "Unicode not supported"; const char *v = "Unicode not supported";
#endif #endif
return 1 + ((where == NULL)? return (int)(1 + ((where == NULL)?
strlen(v): PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v)); strlen(v) : PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v)));
} }
break; break;
@ -206,8 +207,8 @@ switch (what)
const char *v = (XSTRING(Z PCRE2_PRERELEASE)[1] == 0)? const char *v = (XSTRING(Z PCRE2_PRERELEASE)[1] == 0)?
XSTRING(PCRE2_MAJOR.PCRE2_MINOR PCRE2_DATE) : XSTRING(PCRE2_MAJOR.PCRE2_MINOR PCRE2_DATE) :
XSTRING(PCRE2_MAJOR.PCRE2_MINOR) XSTRING(PCRE2_PRERELEASE PCRE2_DATE); XSTRING(PCRE2_MAJOR.PCRE2_MINOR) XSTRING(PCRE2_PRERELEASE PCRE2_DATE);
return 1 + ((where == NULL)? return (int)(1 + ((where == NULL)?
strlen(v) : PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v)); strlen(v) : PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v)));
} }
} }

View File

@ -401,7 +401,7 @@ BOOL utf = FALSE;
BOOL reset_could_continue = FALSE; BOOL reset_could_continue = FALSE;
rlevel++; rlevel++;
offsetcount &= (-2); offsetcount &= (uint32_t)(-2); /* Round down */
wscount -= 2; wscount -= 2;
wscount = (wscount - (wscount % (INTS_PER_STATEBLOCK * 2))) / wscount = (wscount - (wscount % (INTS_PER_STATEBLOCK * 2))) /
@ -439,7 +439,7 @@ if (*first_op == OP_REVERSE)
end_code = this_start_code; end_code = this_start_code;
do do
{ {
size_t back = GET(end_code, 2+LINK_SIZE); size_t back = (size_t)GET(end_code, 2+LINK_SIZE);
if (back > max_back) max_back = back; if (back > max_back) max_back = back;
end_code += GET(end_code, 1); end_code += GET(end_code, 1);
} }
@ -481,11 +481,11 @@ if (*first_op == OP_REVERSE)
end_code = this_start_code; end_code = this_start_code;
do do
{ {
size_t back = GET(end_code, 2+LINK_SIZE); size_t back = (size_t)GET(end_code, 2+LINK_SIZE);
if (back <= gone_back) if (back <= gone_back)
{ {
int bstate = (int)(end_code - start_code + 2 + 2*LINK_SIZE); int bstate = (int)(end_code - start_code + 2 + 2*LINK_SIZE);
ADD_NEW_DATA(-bstate, 0, gone_back - back); ADD_NEW_DATA(-bstate, 0, (int)(gone_back - back));
} }
end_code += GET(end_code, 1); end_code += GET(end_code, 1);
} }
@ -509,7 +509,7 @@ else
do { end_code += GET(end_code, 1); } while (*end_code == OP_ALT); do { end_code += GET(end_code, 1); } while (*end_code == OP_ALT);
new_count = workspace[1]; new_count = workspace[1];
if (!workspace[0]) if (!workspace[0])
memcpy(new_states, active_states, new_count * sizeof(stateblock)); memcpy(new_states, active_states, (size_t)new_count * sizeof(stateblock));
} }
/* Not restarting */ /* Not restarting */
@ -593,8 +593,9 @@ for (;;)
stateblock *current_state = active_states + i; stateblock *current_state = active_states + i;
BOOL caseless = FALSE; BOOL caseless = FALSE;
PCRE2_SPTR code; PCRE2_SPTR code;
uint32_t codevalue;
int state_offset = current_state->offset; int state_offset = current_state->offset;
int codevalue, rrc; int rrc;
int count; int count;
/* A negative offset is a special case meaning "hold off going to this /* A negative offset is a special case meaning "hold off going to this
@ -719,7 +720,7 @@ for (;;)
ADD_ACTIVE(state_offset + 1 + LINK_SIZE, 0); ADD_ACTIVE(state_offset + 1 + LINK_SIZE, 0);
if (codevalue != OP_KET) if (codevalue != OP_KET)
{ {
ADD_ACTIVE(state_offset - GET(code, 1), 0); ADD_ACTIVE(state_offset - (int)GET(code, 1), 0);
} }
} }
else else
@ -733,11 +734,12 @@ for (;;)
else if (match_count > 0 && ++match_count * 2 > (int)offsetcount) else if (match_count > 0 && ++match_count * 2 > (int)offsetcount)
match_count = 0; match_count = 0;
count = ((match_count == 0)? (int)offsetcount : match_count * 2) - 2; count = ((match_count == 0)? (int)offsetcount : match_count * 2) - 2;
if (count > 0) memmove(offsets + 2, offsets, count * sizeof(PCRE2_SIZE)); if (count > 0) memmove(offsets + 2, offsets,
(size_t)count * sizeof(PCRE2_SIZE));
if (offsetcount >= 2) if (offsetcount >= 2)
{ {
offsets[0] = (int)(current_subject - start_subject); offsets[0] = (PCRE2_SIZE)(current_subject - start_subject);
offsets[1] = (int)(ptr - start_subject); offsets[1] = (PCRE2_SIZE)(ptr - start_subject);
} }
if ((mb->moptions & PCRE2_DFA_SHORTEST) != 0) return match_count; if ((mb->moptions & PCRE2_DFA_SHORTEST) != 0) return match_count;
} }
@ -959,7 +961,7 @@ for (;;)
{ {
if (d == '_') left_word = TRUE; else if (d == '_') left_word = TRUE; else
{ {
int cat = UCD_CATEGORY(d); uint32_t cat = UCD_CATEGORY(d);
left_word = (cat == ucp_L || cat == ucp_N); left_word = (cat == ucp_L || cat == ucp_N);
} }
} }
@ -984,7 +986,7 @@ for (;;)
{ {
if (c == '_') right_word = TRUE; else if (c == '_') right_word = TRUE; else
{ {
int cat = UCD_CATEGORY(c); uint32_t cat = UCD_CATEGORY(c);
right_word = (cat == ucp_L || cat == ucp_N); right_word = (cat == ucp_L || cat == ucp_N);
} }
} }
@ -1369,7 +1371,7 @@ for (;;)
if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); } if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); }
if (clen > 0) if (clen > 0)
{ {
int lgb, rgb; uint32_t lgb, rgb;
PCRE2_SPTR nptr = ptr + clen; PCRE2_SPTR nptr = ptr + clen;
int ncount = 0; int ncount = 0;
if (count > 0 && codevalue == OP_EXTUNI_EXTRA + OP_TYPEPOSPLUS) if (count > 0 && codevalue == OP_EXTUNI_EXTRA + OP_TYPEPOSPLUS)
@ -1383,7 +1385,7 @@ for (;;)
dlen = 1; dlen = 1;
if (!utf) d = *nptr; else { GETCHARLEN(d, nptr, dlen); } if (!utf) d = *nptr; else { GETCHARLEN(d, nptr, dlen); }
rgb = UCD_GRAPHBREAK(d); rgb = UCD_GRAPHBREAK(d);
if ((PRIV(ucp_gbtable)[lgb] & (1 << rgb)) == 0) break; if ((PRIV(ucp_gbtable)[lgb] & (1u << rgb)) == 0) break;
ncount++; ncount++;
lgb = rgb; lgb = rgb;
nptr += dlen; nptr += dlen;
@ -1630,7 +1632,7 @@ for (;;)
ADD_ACTIVE(state_offset + 2, 0); ADD_ACTIVE(state_offset + 2, 0);
if (clen > 0) if (clen > 0)
{ {
int lgb, rgb; uint32_t lgb, rgb;
PCRE2_SPTR nptr = ptr + clen; PCRE2_SPTR nptr = ptr + clen;
int ncount = 0; int ncount = 0;
if (codevalue == OP_EXTUNI_EXTRA + OP_TYPEPOSSTAR || if (codevalue == OP_EXTUNI_EXTRA + OP_TYPEPOSSTAR ||
@ -1645,7 +1647,7 @@ for (;;)
dlen = 1; dlen = 1;
if (!utf) d = *nptr; else { GETCHARLEN(d, nptr, dlen); } if (!utf) d = *nptr; else { GETCHARLEN(d, nptr, dlen); }
rgb = UCD_GRAPHBREAK(d); rgb = UCD_GRAPHBREAK(d);
if ((PRIV(ucp_gbtable)[lgb] & (1 << rgb)) == 0) break; if ((PRIV(ucp_gbtable)[lgb] & (1u << rgb)) == 0) break;
ncount++; ncount++;
lgb = rgb; lgb = rgb;
nptr += dlen; nptr += dlen;
@ -1902,7 +1904,7 @@ for (;;)
count = current_state->count; /* Number already matched */ count = current_state->count; /* Number already matched */
if (clen > 0) if (clen > 0)
{ {
int lgb, rgb; uint32_t lgb, rgb;
PCRE2_SPTR nptr = ptr + clen; PCRE2_SPTR nptr = ptr + clen;
int ncount = 0; int ncount = 0;
if (codevalue == OP_EXTUNI_EXTRA + OP_TYPEPOSUPTO) if (codevalue == OP_EXTUNI_EXTRA + OP_TYPEPOSUPTO)
@ -1916,7 +1918,7 @@ for (;;)
dlen = 1; dlen = 1;
if (!utf) d = *nptr; else { GETCHARLEN(d, nptr, dlen); } if (!utf) d = *nptr; else { GETCHARLEN(d, nptr, dlen); }
rgb = UCD_GRAPHBREAK(d); rgb = UCD_GRAPHBREAK(d);
if ((PRIV(ucp_gbtable)[lgb] & (1 << rgb)) == 0) break; if ((PRIV(ucp_gbtable)[lgb] & (1u << rgb)) == 0) break;
ncount++; ncount++;
lgb = rgb; lgb = rgb;
nptr += dlen; nptr += dlen;
@ -2097,7 +2099,7 @@ for (;;)
case OP_EXTUNI: case OP_EXTUNI:
if (clen > 0) if (clen > 0)
{ {
int lgb, rgb; uint32_t lgb, rgb;
PCRE2_SPTR nptr = ptr + clen; PCRE2_SPTR nptr = ptr + clen;
int ncount = 0; int ncount = 0;
lgb = UCD_GRAPHBREAK(c); lgb = UCD_GRAPHBREAK(c);
@ -2106,7 +2108,7 @@ for (;;)
dlen = 1; dlen = 1;
if (!utf) d = *nptr; else { GETCHARLEN(d, nptr, dlen); } if (!utf) d = *nptr; else { GETCHARLEN(d, nptr, dlen); }
rgb = UCD_GRAPHBREAK(d); rgb = UCD_GRAPHBREAK(d);
if ((PRIV(ucp_gbtable)[lgb] & (1 << rgb)) == 0) break; if ((PRIV(ucp_gbtable)[lgb] & (1u << rgb)) == 0) break;
ncount++; ncount++;
lgb = rgb; lgb = rgb;
nptr += dlen; nptr += dlen;
@ -2582,7 +2584,7 @@ for (;;)
mb, /* static match data */ mb, /* static match data */
code, /* this subexpression's code */ code, /* this subexpression's code */
ptr, /* where we currently are */ ptr, /* where we currently are */
(int)(ptr - start_subject), /* start offset */ (PCRE2_SIZE)(ptr - start_subject), /* start offset */
local_offsets, /* offset vector */ local_offsets, /* offset vector */
sizeof(local_offsets)/sizeof(PCRE2_SIZE), /* size of same */ sizeof(local_offsets)/sizeof(PCRE2_SIZE), /* size of same */
local_workspace, /* workspace vector */ local_workspace, /* workspace vector */
@ -2601,8 +2603,8 @@ for (;;)
{ {
PCRE2_SIZE local_offsets[1000]; PCRE2_SIZE local_offsets[1000];
int local_workspace[1000]; int local_workspace[1000];
int codelink = GET(code, 1); int codelink = (int)GET(code, 1);
int condcode; PCRE2_UCHAR condcode;
/* Because of the way auto-callout works during compile, a callout item /* Because of the way auto-callout works during compile, a callout item
is inserted between OP_COND and an assertion condition. This does not is inserted between OP_COND and an assertion condition. This does not
@ -2611,8 +2613,10 @@ for (;;)
if (code[LINK_SIZE + 1] == OP_CALLOUT if (code[LINK_SIZE + 1] == OP_CALLOUT
|| code[LINK_SIZE + 1] == OP_CALLOUT_STR) || code[LINK_SIZE + 1] == OP_CALLOUT_STR)
{ {
unsigned int callout_length = (code[LINK_SIZE + 1] == OP_CALLOUT) PCRE2_SIZE callout_length = (code[LINK_SIZE + 1] == OP_CALLOUT)?
? PRIV(OP_lengths)[OP_CALLOUT] : GET(code, 2 + 3*LINK_SIZE); (PCRE2_SIZE)PRIV(OP_lengths)[OP_CALLOUT] :
(PCRE2_SIZE)GET(code, 2 + 3*LINK_SIZE);
rrc = 0; rrc = 0;
if (mb->callout != NULL) if (mb->callout != NULL)
{ {
@ -2678,7 +2682,7 @@ for (;;)
else if (condcode == OP_RREF) else if (condcode == OP_RREF)
{ {
int value = GET2(code, LINK_SIZE + 2); unsigned int value = GET2(code, LINK_SIZE + 2);
if (value != RREF_ANY) return PCRE2_ERROR_DFA_UCOND; if (value != RREF_ANY) return PCRE2_ERROR_DFA_UCOND;
if (mb->recursive != NULL) if (mb->recursive != NULL)
{ ADD_ACTIVE(state_offset + LINK_SIZE + 2 + IMM2_SIZE, 0); } { ADD_ACTIVE(state_offset + LINK_SIZE + 2 + IMM2_SIZE, 0); }
@ -2699,7 +2703,7 @@ for (;;)
mb, /* fixed match data */ mb, /* fixed match data */
asscode, /* this subexpression's code */ asscode, /* this subexpression's code */
ptr, /* where we currently are */ ptr, /* where we currently are */
(int)(ptr - start_subject), /* start offset */ (PCRE2_SIZE)(ptr - start_subject), /* start offset */
local_offsets, /* offset vector */ local_offsets, /* offset vector */
sizeof(local_offsets)/sizeof(PCRE2_SIZE), /* size of same */ sizeof(local_offsets)/sizeof(PCRE2_SIZE), /* size of same */
local_workspace, /* workspace vector */ local_workspace, /* workspace vector */
@ -2747,7 +2751,7 @@ for (;;)
mb, /* fixed match data */ mb, /* fixed match data */
callpat, /* this subexpression's code */ callpat, /* this subexpression's code */
ptr, /* where we currently are */ ptr, /* where we currently are */
(int)(ptr - start_subject), /* start offset */ (PCRE2_SIZE)(ptr - start_subject), /* start offset */
local_offsets, /* offset vector */ local_offsets, /* offset vector */
sizeof(local_offsets)/sizeof(PCRE2_SIZE), /* size of same */ sizeof(local_offsets)/sizeof(PCRE2_SIZE), /* size of same */
local_workspace, /* workspace vector */ local_workspace, /* workspace vector */
@ -2768,7 +2772,7 @@ for (;;)
{ {
for (rc = rc*2 - 2; rc >= 0; rc -= 2) for (rc = rc*2 - 2; rc >= 0; rc -= 2)
{ {
int charcount = local_offsets[rc+1] - local_offsets[rc]; PCRE2_SIZE charcount = local_offsets[rc+1] - local_offsets[rc];
#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 #if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32
if (utf) if (utf)
{ {
@ -2779,7 +2783,8 @@ for (;;)
#endif #endif
if (charcount > 0) if (charcount > 0)
{ {
ADD_NEW_DATA(-(state_offset + LINK_SIZE + 1), 0, (charcount - 1)); ADD_NEW_DATA(-(state_offset + LINK_SIZE + 1), 0,
(int)(charcount - 1));
} }
else else
{ {
@ -2798,7 +2803,7 @@ for (;;)
case OP_SCBRAPOS: case OP_SCBRAPOS:
case OP_BRAPOSZERO: case OP_BRAPOSZERO:
{ {
int charcount, matched_count; PCRE2_SIZE charcount, matched_count;
PCRE2_SPTR local_ptr = ptr; PCRE2_SPTR local_ptr = ptr;
BOOL allow_zero; BOOL allow_zero;
@ -2821,7 +2826,7 @@ for (;;)
mb, /* fixed match data */ mb, /* fixed match data */
code, /* this subexpression's code */ code, /* this subexpression's code */
local_ptr, /* where we currently are */ local_ptr, /* where we currently are */
(int)(ptr - start_subject), /* start offset */ (PCRE2_SIZE)(ptr - start_subject), /* start offset */
local_offsets, /* offset vector */ local_offsets, /* offset vector */
sizeof(local_offsets)/sizeof(PCRE2_SIZE), /* size of same */ sizeof(local_offsets)/sizeof(PCRE2_SIZE), /* size of same */
local_workspace, /* workspace vector */ local_workspace, /* workspace vector */
@ -2872,11 +2877,11 @@ for (;;)
{ {
PCRE2_SPTR p = ptr; PCRE2_SPTR p = ptr;
PCRE2_SPTR pp = local_ptr; PCRE2_SPTR pp = local_ptr;
charcount = (int)(pp - p); charcount = (PCRE2_SIZE)(pp - p);
#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 #if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32
if (utf) while (p < pp) if (NOT_FIRSTCU(*p++)) charcount--; if (utf) while (p < pp) if (NOT_FIRSTCU(*p++)) charcount--;
#endif #endif
ADD_NEW_DATA(-next_state_offset, 0, (charcount - 1)); ADD_NEW_DATA(-next_state_offset, 0, (int)(charcount - 1));
} }
} }
} }
@ -2893,7 +2898,7 @@ for (;;)
mb, /* fixed match data */ mb, /* fixed match data */
code, /* this subexpression's code */ code, /* this subexpression's code */
ptr, /* where we currently are */ ptr, /* where we currently are */
(int)(ptr - start_subject), /* start offset */ (PCRE2_SIZE)(ptr - start_subject), /* start offset */
local_offsets, /* offset vector */ local_offsets, /* offset vector */
sizeof(local_offsets)/sizeof(PCRE2_SIZE), /* size of same */ sizeof(local_offsets)/sizeof(PCRE2_SIZE), /* size of same */
local_workspace, /* workspace vector */ local_workspace, /* workspace vector */
@ -2903,7 +2908,7 @@ for (;;)
if (rc >= 0) if (rc >= 0)
{ {
PCRE2_SPTR end_subpattern = code; PCRE2_SPTR end_subpattern = code;
int charcount = local_offsets[1] - local_offsets[0]; PCRE2_SIZE charcount = local_offsets[1] - local_offsets[0];
int next_state_offset, repeat_state_offset; int next_state_offset, repeat_state_offset;
do { end_subpattern += GET(end_subpattern, 1); } do { end_subpattern += GET(end_subpattern, 1); }
@ -2963,9 +2968,9 @@ for (;;)
while (p < pp) if (NOT_FIRSTCU(*p++)) charcount--; while (p < pp) if (NOT_FIRSTCU(*p++)) charcount--;
} }
#endif #endif
ADD_NEW_DATA(-next_state_offset, 0, (charcount - 1)); ADD_NEW_DATA(-next_state_offset, 0, (int)(charcount - 1));
if (repeat_state_offset >= 0) if (repeat_state_offset >= 0)
{ ADD_NEW_DATA(-repeat_state_offset, 0, (charcount - 1)); } { ADD_NEW_DATA(-repeat_state_offset, 0, (int)(charcount - 1)); }
} }
} }
else if (rc != PCRE2_ERROR_NOMATCH) return rc; else if (rc != PCRE2_ERROR_NOMATCH) return rc;
@ -3018,7 +3023,7 @@ for (;;)
return rrc; /* Abandon */ return rrc; /* Abandon */
} }
if (rrc == 0) if (rrc == 0)
{ ADD_ACTIVE(state_offset + callout_length, 0); } { ADD_ACTIVE(state_offset + (int)callout_length, 0); }
} }
break; break;
@ -3307,10 +3312,10 @@ if (utf && (options & PCRE2_NO_UTF_CHECK) == 0)
offset to be an absolute offset in the whole string. */ offset to be an absolute offset in the whole string. */
match_data->rc = PRIV(valid_utf)(check_subject, match_data->rc = PRIV(valid_utf)(check_subject,
length - (check_subject - subject), &(match_data->startchar)); length - (PCRE2_SIZE)(check_subject - subject), &(match_data->startchar));
if (match_data->rc != 0) if (match_data->rc != 0)
{ {
match_data->startchar += check_subject - subject; match_data->startchar += (PCRE2_SIZE)(check_subject - subject);
return match_data->rc; return match_data->rc;
} }
} }
@ -3332,7 +3337,8 @@ if (!anchored)
{ {
first_cu2 = TABLE_GET(first_cu, mb->tables + fcc_offset, first_cu); first_cu2 = TABLE_GET(first_cu, mb->tables + fcc_offset, first_cu);
#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 8 #if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 8
if (utf && first_cu > 127) first_cu2 = UCD_OTHERCASE(first_cu); if (utf && first_cu > 127)
first_cu2 = (PCRE2_UCHAR)UCD_OTHERCASE(first_cu);
#endif #endif
} }
} }
@ -3352,7 +3358,7 @@ if ((re->flags & PCRE2_LASTSET) != 0)
{ {
req_cu2 = TABLE_GET(req_cu, mb->tables + fcc_offset, req_cu); req_cu2 = TABLE_GET(req_cu, mb->tables + fcc_offset, req_cu);
#if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 8 #if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 8
if (utf && req_cu > 127) req_cu2 = UCD_OTHERCASE(req_cu); if (utf && req_cu > 127) req_cu2 = (PCRE2_UCHAR)UCD_OTHERCASE(req_cu);
#endif #endif
} }
} }
@ -3560,9 +3566,9 @@ for (;;)
start_match, /* where we currently are */ start_match, /* where we currently are */
start_offset, /* start offset in subject */ start_offset, /* start offset in subject */
match_data->ovector, /* offset vector */ match_data->ovector, /* offset vector */
match_data->oveccount * 2, /* actual size of same */ (uint32_t)match_data->oveccount * 2, /* actual size of same */
workspace, /* workspace vector */ workspace, /* workspace vector */
wscount, /* size of same */ (int)wscount, /* size of same */
0); /* function recurse level */ 0); /* function recurse level */
/* Anything other than "no match" means we are done, always; otherwise, carry /* Anything other than "no match" means we are done, always; otherwise, carry
@ -3576,7 +3582,7 @@ for (;;)
match_data->ovector[1] = (PCRE2_SIZE)(end_subject - subject); match_data->ovector[1] = (PCRE2_SIZE)(end_subject - subject);
} }
match_data->leftchar = (PCRE2_SIZE)(mb->start_used_ptr - subject); match_data->leftchar = (PCRE2_SIZE)(mb->start_used_ptr - subject);
match_data->rightchar = mb->last_used_ptr - subject; match_data->rightchar = (PCRE2_SIZE)( mb->last_used_ptr - subject);
match_data->startchar = (PCRE2_SIZE)(start_match - subject); match_data->startchar = (PCRE2_SIZE)(start_match - subject);
match_data->rc = rc; match_data->rc = rc;
return rc; return rc;

View File

@ -62,7 +62,7 @@ Each substring ends with \0 to insert a null character. This includes the final
substring, so that the whole string ends with \0\0, which can be detected when substring, so that the whole string ends with \0\0, which can be detected when
counting through. */ counting through. */
static const char compile_error_texts[] = static const unsigned char compile_error_texts[] =
"no error\0" "no error\0"
"\\ at end of pattern\0" "\\ at end of pattern\0"
"\\c at end of pattern\0" "\\c at end of pattern\0"
@ -177,7 +177,7 @@ static const char compile_error_texts[] =
/* Match-time and UTF error texts are in the same format. */ /* Match-time and UTF error texts are in the same format. */
static const char match_error_texts[] = static const unsigned char match_error_texts[] =
"no error\0" "no error\0"
"no match\0" "no match\0"
"partial match\0" "partial match\0"
@ -277,9 +277,9 @@ PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
pcre2_get_error_message(int enumber, PCRE2_UCHAR *buffer, size_t size) pcre2_get_error_message(int enumber, PCRE2_UCHAR *buffer, size_t size)
{ {
char xbuff[128]; char xbuff[128];
const char *message; const unsigned char *message;
size_t i; size_t i;
uint32_t n; int n;
if (size == 0) return PCRE2_ERROR_NOMEMORY; if (size == 0) return PCRE2_ERROR_NOMEMORY;
@ -315,7 +315,7 @@ for (i = 0; *message != 0; i++)
} }
buffer[i] = 0; buffer[i] = 0;
return i; return (int)i;
} }
/* End of pcre2_error.c */ /* End of pcre2_error.c */

View File

@ -269,21 +269,21 @@ advancing the pointer. */
#define GETUTF8(c, eptr) \ #define GETUTF8(c, eptr) \
{ \ { \
if ((c & 0x20) == 0) \ if ((c & 0x20u) == 0) \
c = ((c & 0x1f) << 6) | (eptr[1] & 0x3f); \ c = ((c & 0x1fu) << 6) | (eptr[1] & 0x3fu); \
else if ((c & 0x10) == 0) \ else if ((c & 0x10u) == 0) \
c = ((c & 0x0f) << 12) | ((eptr[1] & 0x3f) << 6) | (eptr[2] & 0x3f); \ c = ((c & 0x0fu) << 12) | ((eptr[1] & 0x3fu) << 6) | (eptr[2] & 0x3fu); \
else if ((c & 0x08) == 0) \ else if ((c & 0x08u) == 0) \
c = ((c & 0x07) << 18) | ((eptr[1] & 0x3f) << 12) | \ c = ((c & 0x07u) << 18) | ((eptr[1] & 0x3fu) << 12) | \
((eptr[2] & 0x3f) << 6) | (eptr[3] & 0x3f); \ ((eptr[2] & 0x3fu) << 6) | (eptr[3] & 0x3fu); \
else if ((c & 0x04) == 0) \ else if ((c & 0x04u) == 0) \
c = ((c & 0x03) << 24) | ((eptr[1] & 0x3f) << 18) | \ c = ((c & 0x03u) << 24) | ((eptr[1] & 0x3fu) << 18) | \
((eptr[2] & 0x3f) << 12) | ((eptr[3] & 0x3f) << 6) | \ ((eptr[2] & 0x3fu) << 12) | ((eptr[3] & 0x3fu) << 6) | \
(eptr[4] & 0x3f); \ (eptr[4] & 0x3fu); \
else \ else \
c = ((c & 0x01) << 30) | ((eptr[1] & 0x3f) << 24) | \ c = ((c & 0x01u) << 30) | ((eptr[1] & 0x3fu) << 24) | \
((eptr[2] & 0x3f) << 18) | ((eptr[3] & 0x3f) << 12) | \ ((eptr[2] & 0x3fu) << 18) | ((eptr[3] & 0x3fu) << 12) | \
((eptr[4] & 0x3f) << 6) | (eptr[5] & 0x3f); \ ((eptr[4] & 0x3fu) << 6) | (eptr[5] & 0x3fu); \
} }
/* Base macro to pick up the remaining bytes of a UTF-8 character, advancing /* Base macro to pick up the remaining bytes of a UTF-8 character, advancing
@ -291,31 +291,31 @@ the pointer. */
#define GETUTF8INC(c, eptr) \ #define GETUTF8INC(c, eptr) \
{ \ { \
if ((c & 0x20) == 0) \ if ((c & 0x20u) == 0) \
c = ((c & 0x1f) << 6) | (*eptr++ & 0x3f); \ c = ((c & 0x1fu) << 6) | (*eptr++ & 0x3fu); \
else if ((c & 0x10) == 0) \ else if ((c & 0x10u) == 0) \
{ \ { \
c = ((c & 0x0f) << 12) | ((*eptr & 0x3f) << 6) | (eptr[1] & 0x3f); \ c = ((c & 0x0fu) << 12) | ((*eptr & 0x3fu) << 6) | (eptr[1] & 0x3fu); \
eptr += 2; \ eptr += 2; \
} \ } \
else if ((c & 0x08) == 0) \ else if ((c & 0x08u) == 0) \
{ \ { \
c = ((c & 0x07) << 18) | ((*eptr & 0x3f) << 12) | \ c = ((c & 0x07u) << 18) | ((*eptr & 0x3fu) << 12) | \
((eptr[1] & 0x3f) << 6) | (eptr[2] & 0x3f); \ ((eptr[1] & 0x3fu) << 6) | (eptr[2] & 0x3fu); \
eptr += 3; \ eptr += 3; \
} \ } \
else if ((c & 0x04) == 0) \ else if ((c & 0x04u) == 0) \
{ \ { \
c = ((c & 0x03) << 24) | ((*eptr & 0x3f) << 18) | \ c = ((c & 0x03u) << 24) | ((*eptr & 0x3fu) << 18) | \
((eptr[1] & 0x3f) << 12) | ((eptr[2] & 0x3f) << 6) | \ ((eptr[1] & 0x3fu) << 12) | ((eptr[2] & 0x3fu) << 6) | \
(eptr[3] & 0x3f); \ (eptr[3] & 0x3fu); \
eptr += 4; \ eptr += 4; \
} \ } \
else \ else \
{ \ { \
c = ((c & 0x01) << 30) | ((*eptr & 0x3f) << 24) | \ c = ((c & 0x01u) << 30) | ((*eptr & 0x3fu) << 24) | \
((eptr[1] & 0x3f) << 18) | ((eptr[2] & 0x3f) << 12) | \ ((eptr[1] & 0x3fu) << 18) | ((eptr[2] & 0x3fu) << 12) | \
((eptr[3] & 0x3f) << 6) | (eptr[4] & 0x3f); \ ((eptr[3] & 0x3fu) << 6) | (eptr[4] & 0x3fu); \
eptr += 5; \ eptr += 5; \
} \ } \
} }
@ -325,34 +325,34 @@ advancing the pointer, incrementing the length. */
#define GETUTF8LEN(c, eptr, len) \ #define GETUTF8LEN(c, eptr, len) \
{ \ { \
if ((c & 0x20) == 0) \ if ((c & 0x20u) == 0) \
{ \ { \
c = ((c & 0x1f) << 6) | (eptr[1] & 0x3f); \ c = ((c & 0x1fu) << 6) | (eptr[1] & 0x3fu); \
len++; \ len++; \
} \ } \
else if ((c & 0x10) == 0) \ else if ((c & 0x10u) == 0) \
{ \ { \
c = ((c & 0x0f) << 12) | ((eptr[1] & 0x3f) << 6) | (eptr[2] & 0x3f); \ c = ((c & 0x0fu) << 12) | ((eptr[1] & 0x3fu) << 6) | (eptr[2] & 0x3fu); \
len += 2; \ len += 2; \
} \ } \
else if ((c & 0x08) == 0) \ else if ((c & 0x08u) == 0) \
{\ {\
c = ((c & 0x07) << 18) | ((eptr[1] & 0x3f) << 12) | \ c = ((c & 0x07u) << 18) | ((eptr[1] & 0x3fu) << 12) | \
((eptr[2] & 0x3f) << 6) | (eptr[3] & 0x3f); \ ((eptr[2] & 0x3fu) << 6) | (eptr[3] & 0x3fu); \
len += 3; \ len += 3; \
} \ } \
else if ((c & 0x04) == 0) \ else if ((c & 0x04u) == 0) \
{ \ { \
c = ((c & 0x03) << 24) | ((eptr[1] & 0x3f) << 18) | \ c = ((c & 0x03u) << 24) | ((eptr[1] & 0x3fu) << 18) | \
((eptr[2] & 0x3f) << 12) | ((eptr[3] & 0x3f) << 6) | \ ((eptr[2] & 0x3fu) << 12) | ((eptr[3] & 0x3fu) << 6) | \
(eptr[4] & 0x3f); \ (eptr[4] & 0x3fu); \
len += 4; \ len += 4; \
} \ } \
else \ else \
{\ {\
c = ((c & 0x01) << 30) | ((eptr[1] & 0x3f) << 24) | \ c = ((c & 0x01u) << 30) | ((eptr[1] & 0x3fu) << 24) | \
((eptr[2] & 0x3f) << 18) | ((eptr[3] & 0x3f) << 12) | \ ((eptr[2] & 0x3fu) << 18) | ((eptr[3] & 0x3fu) << 12) | \
((eptr[4] & 0x3f) << 6) | (eptr[5] & 0x3f); \ ((eptr[4] & 0x3fu) << 6) | (eptr[5] & 0x3fu); \
len += 5; \ len += 5; \
} \ } \
} }

View File

@ -94,7 +94,7 @@ easier to maintain, the storing and loading of offsets from the compiled code
unit string is now handled by the macros that are defined here. unit string is now handled by the macros that are defined here.
The macros are controlled by the value of LINK_SIZE. This defaults to 2, but The macros are controlled by the value of LINK_SIZE. This defaults to 2, but
values of 2 or 4 are also supported. */ values of 3 or 4 are also supported. */
/* ------------------- 8-bit support ------------------ */ /* ------------------- 8-bit support ------------------ */
@ -102,29 +102,29 @@ values of 2 or 4 are also supported. */
#if LINK_SIZE == 2 #if LINK_SIZE == 2
#define PUT(a,n,d) \ #define PUT(a,n,d) \
(a[n] = (d) >> 8), \ (a[n] = (PCRE2_UCHAR)((d) >> 8)), \
(a[(n)+1] = (d) & 255) (a[(n)+1] = (PCRE2_UCHAR)((d) & 255))
#define GET(a,n) \ #define GET(a,n) \
(((a)[n] << 8) | (a)[(n)+1]) (unsigned int)(((a)[n] << 8) | (a)[(n)+1])
#define MAX_PATTERN_SIZE (1 << 16) #define MAX_PATTERN_SIZE (1 << 16)
#elif LINK_SIZE == 3 #elif LINK_SIZE == 3
#define PUT(a,n,d) \ #define PUT(a,n,d) \
(a[n] = (d) >> 16), \ (a[n] = (PCRE2_UCHAR)((d) >> 16)), \
(a[(n)+1] = (d) >> 8), \ (a[(n)+1] = (PCRE2_UCHAR)((d) >> 8)), \
(a[(n)+2] = (d) & 255) (a[(n)+2] = (PCRE2_UCHAR)((d) & 255))
#define GET(a,n) \ #define GET(a,n) \
(((a)[n] << 16) | ((a)[(n)+1] << 8) | (a)[(n)+2]) (unsigned int)(((a)[n] << 16) | ((a)[(n)+1] << 8) | (a)[(n)+2])
#define MAX_PATTERN_SIZE (1 << 24) #define MAX_PATTERN_SIZE (1 << 24)
#elif LINK_SIZE == 4 #elif LINK_SIZE == 4
#define PUT(a,n,d) \ #define PUT(a,n,d) \
(a[n] = (d) >> 24), \ (a[n] = (PCRE2_UCHAR)((d) >> 24)), \
(a[(n)+1] = (d) >> 16), \ (a[(n)+1] = (PCRE2_UCHAR)((d) >> 16)), \
(a[(n)+2] = (d) >> 8), \ (a[(n)+2] = (PCRE2_UCHAR)((d) >> 8)), \
(a[(n)+3] = (d) & 255) (a[(n)+3] = (PCRE2_UCHAR)((d) & 255))
#define GET(a,n) \ #define GET(a,n) \
(((a)[n] << 24) | ((a)[(n)+1] << 16) | ((a)[(n)+2] << 8) | (a)[(n)+3]) (unsigned int)(((a)[n] << 24) | ((a)[(n)+1] << 16) | ((a)[(n)+2] << 8) | (a)[(n)+3])
#define MAX_PATTERN_SIZE (1 << 30) /* Keep it positive */ #define MAX_PATTERN_SIZE (1 << 30) /* Keep it positive */
#else #else
@ -149,10 +149,10 @@ values of 2 or 4 are also supported. */
#undef LINK_SIZE #undef LINK_SIZE
#define LINK_SIZE 2 #define LINK_SIZE 2
#define PUT(a,n,d) \ #define PUT(a,n,d) \
(a[n] = (d) >> 16), \ (a[n] = (PCRE2_UCHAR)((d) >> 16)), \
(a[(n)+1] = (d) & 65535) (a[(n)+1] = (PCRE2_UCHAR)((d) & 65535))
#define GET(a,n) \ #define GET(a,n) \
(((a)[n] << 16) | (a)[(n)+1]) (unsigned int)(((a)[n] << 16) | (a)[(n)+1])
#define MAX_PATTERN_SIZE (1 << 30) /* Keep it positive */ #define MAX_PATTERN_SIZE (1 << 30) /* Keep it positive */
#else #else
@ -283,47 +283,47 @@ UTF support is omitted, we don't even define them. */
/* Returns with the additional number of characters if IS_MULTICHAR(c) is TRUE. /* Returns with the additional number of characters if IS_MULTICHAR(c) is TRUE.
Otherwise it has an undefined behaviour. */ Otherwise it has an undefined behaviour. */
#define GET_EXTRALEN(c) (PRIV(utf8_table4)[(c) & 0x3f]) #define GET_EXTRALEN(c) (PRIV(utf8_table4)[(c) & 0x3fu])
/* Returns TRUE, if the given value is not the first code unit of a UTF /* Returns TRUE, if the given value is not the first code unit of a UTF
sequence. */ sequence. */
#define NOT_FIRSTCU(c) (((c) & 0xc0) == 0x80) #define NOT_FIRSTCU(c) (((c) & 0xc0u) == 0x80u)
/* Get the next UTF-8 character, not advancing the pointer. This is called when /* Get the next UTF-8 character, not advancing the pointer. This is called when
we know we are in UTF-8 mode. */ we know we are in UTF-8 mode. */
#define GETCHAR(c, eptr) \ #define GETCHAR(c, eptr) \
c = *eptr; \ c = *eptr; \
if (c >= 0xc0) GETUTF8(c, eptr); if (c >= 0xc0u) GETUTF8(c, eptr);
/* Get the next UTF-8 character, testing for UTF-8 mode, and not advancing the /* Get the next UTF-8 character, testing for UTF-8 mode, and not advancing the
pointer. */ pointer. */
#define GETCHARTEST(c, eptr) \ #define GETCHARTEST(c, eptr) \
c = *eptr; \ c = *eptr; \
if (utf && c >= 0xc0) GETUTF8(c, eptr); if (utf && c >= 0xc0u) GETUTF8(c, eptr);
/* Get the next UTF-8 character, advancing the pointer. This is called when we /* Get the next UTF-8 character, advancing the pointer. This is called when we
know we are in UTF-8 mode. */ know we are in UTF-8 mode. */
#define GETCHARINC(c, eptr) \ #define GETCHARINC(c, eptr) \
c = *eptr++; \ c = *eptr++; \
if (c >= 0xc0) GETUTF8INC(c, eptr); if (c >= 0xc0u) GETUTF8INC(c, eptr);
/* Get the next character, testing for UTF-8 mode, and advancing the pointer. /* Get the next character, testing for UTF-8 mode, and advancing the pointer.
This is called when we don't know if we are in UTF-8 mode. */ This is called when we don't know if we are in UTF-8 mode. */
#define GETCHARINCTEST(c, eptr) \ #define GETCHARINCTEST(c, eptr) \
c = *eptr++; \ c = *eptr++; \
if (utf && c >= 0xc0) GETUTF8INC(c, eptr); if (utf && c >= 0xc0u) GETUTF8INC(c, eptr);
/* Get the next UTF-8 character, not advancing the pointer, incrementing length /* Get the next UTF-8 character, not advancing the pointer, incrementing length
if there are extra bytes. This is called when we know we are in UTF-8 mode. */ if there are extra bytes. This is called when we know we are in UTF-8 mode. */
#define GETCHARLEN(c, eptr, len) \ #define GETCHARLEN(c, eptr, len) \
c = *eptr; \ c = *eptr; \
if (c >= 0xc0) GETUTF8LEN(c, eptr, len); if (c >= 0xc0u) GETUTF8LEN(c, eptr, len);
/* Get the next UTF-8 character, testing for UTF-8 mode, not advancing the /* Get the next UTF-8 character, testing for UTF-8 mode, not advancing the
pointer, incrementing length if there are extra bytes. This is called when we pointer, incrementing length if there are extra bytes. This is called when we
@ -331,21 +331,21 @@ do not know if we are in UTF-8 mode. */
#define GETCHARLENTEST(c, eptr, len) \ #define GETCHARLENTEST(c, eptr, len) \
c = *eptr; \ c = *eptr; \
if (utf && c >= 0xc0) GETUTF8LEN(c, eptr, len); if (utf && c >= 0xc0u) GETUTF8LEN(c, eptr, len);
/* If the pointer is not at the start of a character, move it back until /* If the pointer is not at the start of a character, move it back until
it is. This is called only in UTF-8 mode - we don't put a test within the macro it is. This is called only in UTF-8 mode - we don't put a test within the macro
because almost all calls are already within a block of UTF-8 only code. */ because almost all calls are already within a block of UTF-8 only code. */
#define BACKCHAR(eptr) while((*eptr & 0xc0) == 0x80) eptr-- #define BACKCHAR(eptr) while((*eptr & 0xc0u) == 0x80u) eptr--
/* Same as above, just in the other direction. */ /* Same as above, just in the other direction. */
#define FORWARDCHAR(eptr) while((*eptr & 0xc0) == 0x80) eptr++ #define FORWARDCHAR(eptr) while((*eptr & 0xc0u) == 0x80u) eptr++
#define FORWARDCHARTEST(eptr,end) while(eptr < end && (*eptr & 0xc0) == 0x80) eptr++ #define FORWARDCHARTEST(eptr,end) while(eptr < end && (*eptr & 0xc0u) == 0x80u) eptr++
/* Same as above, but it allows a fully customizable form. */ /* Same as above, but it allows a fully customizable form. */
#define ACROSSCHAR(condition, eptr, action) \ #define ACROSSCHAR(condition, eptr, action) \
while((condition) && ((eptr) & 0xc0) == 0x80) action while((condition) && ((eptr) & 0xc0u) == 0x80u) action
/* Deposit a character into memory, returning the number of code units. */ /* Deposit a character into memory, returning the number of code units. */
@ -364,7 +364,7 @@ because almost all calls are already within a block of UTF-8 only code. */
/* Tests whether the code point needs extra characters to decode. */ /* Tests whether the code point needs extra characters to decode. */
#define HAS_EXTRALEN(c) (((c) & 0xfc00) == 0xd800) #define HAS_EXTRALEN(c) (((c) & 0xfc00u) == 0xd800u)
/* Returns with the additional number of characters if IS_MULTICHAR(c) is TRUE. /* Returns with the additional number of characters if IS_MULTICHAR(c) is TRUE.
Otherwise it has an undefined behaviour. */ Otherwise it has an undefined behaviour. */
@ -374,53 +374,53 @@ Otherwise it has an undefined behaviour. */
/* Returns TRUE, if the given value is not the first code unit of a UTF /* Returns TRUE, if the given value is not the first code unit of a UTF
sequence. */ sequence. */
#define NOT_FIRSTCU(c) (((c) & 0xfc00) == 0xdc00) #define NOT_FIRSTCU(c) (((c) & 0xfc00u) == 0xdc00u)
/* Base macro to pick up the low surrogate of a UTF-16 character, not /* Base macro to pick up the low surrogate of a UTF-16 character, not
advancing the pointer. */ advancing the pointer. */
#define GETUTF16(c, eptr) \ #define GETUTF16(c, eptr) \
{ c = (((c & 0x3ff) << 10) | (eptr[1] & 0x3ff)) + 0x10000; } { c = (((c & 0x3ffu) << 10) | (eptr[1] & 0x3ffu)) + 0x10000u; }
/* Get the next UTF-16 character, not advancing the pointer. This is called when /* Get the next UTF-16 character, not advancing the pointer. This is called when
we know we are in UTF-16 mode. */ we know we are in UTF-16 mode. */
#define GETCHAR(c, eptr) \ #define GETCHAR(c, eptr) \
c = *eptr; \ c = *eptr; \
if ((c & 0xfc00) == 0xd800) GETUTF16(c, eptr); if ((c & 0xfc00u) == 0xd800u) GETUTF16(c, eptr);
/* Get the next UTF-16 character, testing for UTF-16 mode, and not advancing the /* Get the next UTF-16 character, testing for UTF-16 mode, and not advancing the
pointer. */ pointer. */
#define GETCHARTEST(c, eptr) \ #define GETCHARTEST(c, eptr) \
c = *eptr; \ c = *eptr; \
if (utf && (c & 0xfc00) == 0xd800) GETUTF16(c, eptr); if (utf && (c & 0xfc00u) == 0xd800u) GETUTF16(c, eptr);
/* Base macro to pick up the low surrogate of a UTF-16 character, advancing /* Base macro to pick up the low surrogate of a UTF-16 character, advancing
the pointer. */ the pointer. */
#define GETUTF16INC(c, eptr) \ #define GETUTF16INC(c, eptr) \
{ c = (((c & 0x3ff) << 10) | (*eptr++ & 0x3ff)) + 0x10000; } { c = (((c & 0x3ffu) << 10) | (*eptr++ & 0x3ffu)) + 0x10000u; }
/* Get the next UTF-16 character, advancing the pointer. This is called when we /* Get the next UTF-16 character, advancing the pointer. This is called when we
know we are in UTF-16 mode. */ know we are in UTF-16 mode. */
#define GETCHARINC(c, eptr) \ #define GETCHARINC(c, eptr) \
c = *eptr++; \ c = *eptr++; \
if ((c & 0xfc00) == 0xd800) GETUTF16INC(c, eptr); if ((c & 0xfc00u) == 0xd800u) GETUTF16INC(c, eptr);
/* Get the next character, testing for UTF-16 mode, and advancing the pointer. /* Get the next character, testing for UTF-16 mode, and advancing the pointer.
This is called when we don't know if we are in UTF-16 mode. */ This is called when we don't know if we are in UTF-16 mode. */
#define GETCHARINCTEST(c, eptr) \ #define GETCHARINCTEST(c, eptr) \
c = *eptr++; \ c = *eptr++; \
if (utf && (c & 0xfc00) == 0xd800) GETUTF16INC(c, eptr); if (utf && (c & 0xfc00u) == 0xd800u) GETUTF16INC(c, eptr);
/* Base macro to pick up the low surrogate of a UTF-16 character, not /* Base macro to pick up the low surrogate of a UTF-16 character, not
advancing the pointer, incrementing the length. */ advancing the pointer, incrementing the length. */
#define GETUTF16LEN(c, eptr, len) \ #define GETUTF16LEN(c, eptr, len) \
{ c = (((c & 0x3ff) << 10) | (eptr[1] & 0x3ff)) + 0x10000; len++; } { c = (((c & 0x3ffu) << 10) | (eptr[1] & 0x3ffu)) + 0x10000u; len++; }
/* Get the next UTF-16 character, not advancing the pointer, incrementing /* Get the next UTF-16 character, not advancing the pointer, incrementing
length if there is a low surrogate. This is called when we know we are in length if there is a low surrogate. This is called when we know we are in
@ -428,7 +428,7 @@ UTF-16 mode. */
#define GETCHARLEN(c, eptr, len) \ #define GETCHARLEN(c, eptr, len) \
c = *eptr; \ c = *eptr; \
if ((c & 0xfc00) == 0xd800) GETUTF16LEN(c, eptr, len); if ((c & 0xfc00u) == 0xd800u) GETUTF16LEN(c, eptr, len);
/* Get the next UTF-816character, testing for UTF-16 mode, not advancing the /* Get the next UTF-816character, testing for UTF-16 mode, not advancing the
pointer, incrementing length if there is a low surrogate. This is called when pointer, incrementing length if there is a low surrogate. This is called when
@ -436,22 +436,22 @@ we do not know if we are in UTF-16 mode. */
#define GETCHARLENTEST(c, eptr, len) \ #define GETCHARLENTEST(c, eptr, len) \
c = *eptr; \ c = *eptr; \
if (utf && (c & 0xfc00) == 0xd800) GETUTF16LEN(c, eptr, len); if (utf && (c & 0xfc00u) == 0xd800u) GETUTF16LEN(c, eptr, len);
/* If the pointer is not at the start of a character, move it back until /* If the pointer is not at the start of a character, move it back until
it is. This is called only in UTF-16 mode - we don't put a test within the it is. This is called only in UTF-16 mode - we don't put a test within the
macro because almost all calls are already within a block of UTF-16 only macro because almost all calls are already within a block of UTF-16 only
code. */ code. */
#define BACKCHAR(eptr) if ((*eptr & 0xfc00) == 0xdc00) eptr-- #define BACKCHAR(eptr) if ((*eptr & 0xfc00u) == 0xdc00u) eptr--
/* Same as above, just in the other direction. */ /* Same as above, just in the other direction. */
#define FORWARDCHAR(eptr) if ((*eptr & 0xfc00) == 0xdc00) eptr++ #define FORWARDCHAR(eptr) if ((*eptr & 0xfc00u) == 0xdc00u) eptr++
#define FORWARDCHARTEST(eptr,end) if (eptr < end && (*eptr & 0xfc00) == 0xdc00) eptr++ #define FORWARDCHARTEST(eptr,end) if (eptr < end && (*eptr & 0xfc00u) == 0xdc00u) eptr++
/* Same as above, but it allows a fully customizable form. */ /* Same as above, but it allows a fully customizable form. */
#define ACROSSCHAR(condition, eptr, action) \ #define ACROSSCHAR(condition, eptr, action) \
if ((condition) && ((eptr) & 0xfc00) == 0xdc00) action if ((condition) && ((eptr) & 0xfc00u) == 0xdc00u) action
/* Deposit a character into memory, returning the number of code units. */ /* Deposit a character into memory, returning the number of code units. */