Skip to content

Commit

Permalink
Try and fix my XCLASS misunderstandings
Browse files Browse the repository at this point in the history
  • Loading branch information
NWilson committed Nov 29, 2024
1 parent 81b1169 commit 7056cdf
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/pcre2_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -6466,7 +6466,7 @@ for (;; pptr++)
/* Now emit the OP_CLASS/OP_NCLASS/OP_XCLASS/OP_ALLANY opcode. */

pptr = PRIV(compile_class_not_nested)(options, xoptions, pptr + 1,
&code, meta == META_CLASS_NOT,
&code, meta == META_CLASS_NOT, FALSE,
errorcodeptr, cb, lengthptr);
if (pptr == NULL) return 0;
PCRE2_ASSERT(*pptr == META_CLASS_END);
Expand Down
2 changes: 1 addition & 1 deletion src/pcre2_compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ void PRIV(update_classbits)(uint32_t ptype, uint32_t pdata, BOOL negated,
OP_CLASS, OP_NCLASS, OP_XCLASS, or OP_ALLANY into pcode. */

uint32_t *PRIV(compile_class_not_nested)(uint32_t options, uint32_t xoptions,
uint32_t *start_ptr, PCRE2_UCHAR **pcode, BOOL negate_class,
uint32_t *start_ptr, PCRE2_UCHAR **pcode, BOOL negate_class, BOOL always_map,
int *errorcodeptr, compile_block *cb, PCRE2_SIZE *lengthptr);

/* Compile the META codes in pptr into opcodes written to pcode. The pptr must
Expand Down
7 changes: 4 additions & 3 deletions src/pcre2_compile_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ become a single OP_CLASS OP_NCLASS, OP_XCLASS, or OP_ALLANY. */

uint32_t *
PRIV(compile_class_not_nested)(uint32_t options, uint32_t xoptions,
uint32_t *start_ptr, PCRE2_UCHAR **pcode, BOOL negate_class,
uint32_t *start_ptr, PCRE2_UCHAR **pcode, BOOL negate_class, BOOL always_map,
int *errorcodeptr, compile_block *cb, PCRE2_SIZE *lengthptr)
{
uint32_t *pptr = start_ptr;
Expand Down Expand Up @@ -1637,7 +1637,8 @@ if ((xclass_props & XCLASS_REQUIRED) != 0)
/* If the map is required, move up the extra data to make room for it;
otherwise just move the code pointer to the end of the extra data. */

if ((xclass_props & XCLASS_HAS_8BIT_CHARS) != 0)
if ((xclass_props & XCLASS_HAS_8BIT_CHARS) != 0 ||
always_map)
{
*code++ |= XCL_MAP;
(void)memmove(code + (32 / sizeof(PCRE2_UCHAR)), code,
Expand Down Expand Up @@ -2079,7 +2080,7 @@ switch (meta)
prev_ptr = ptr;
ptr = PRIV(compile_class_not_nested)(options, xoptions, ptr, &code,
(meta != META_CLASS_NOT) == negated,
errorcodeptr, cb, lengthptr);
TRUE, errorcodeptr, cb, lengthptr);
if (ptr == NULL) return FALSE;

/* We must have a 100% guarantee that ptr increases when
Expand Down
17 changes: 6 additions & 11 deletions src/pcre2_xclass.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,15 @@ const uint8_t *next_char;
utf = TRUE;
#endif

/* Code points < 256 are matched against a bitmap, if one is present. If no
bitmap is present, then the XCLASS does not match any code points < 256. */

if (c < 256)
{
if ((*data & XCL_MAP) != 0)
return (((const uint8_t *)data+1)[c/8] & (1u << (c&7))) != 0;
return FALSE;
}

/* Skip the bitmap. */
/* Code points < 256 are matched against a bitmap, if one is present. */

if ((*data++ & XCL_MAP) != 0)
{
if (c < 256)
return (((const uint8_t *)data)[c/8] & (1u << (c&7))) != 0;
/* Skip bitmap. */
data += 32 / sizeof(PCRE2_UCHAR);
}

/* Match against the list of Unicode properties. We won't ever
encounter XCL_PROP or XCL_NOTPROP when UTF support is not compiled. */
Expand Down

0 comments on commit 7056cdf

Please sign in to comment.