Skip to content

Commit 7056cdf

Browse files
committed
Try and fix my XCLASS misunderstandings
1 parent 81b1169 commit 7056cdf

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
lines changed

src/pcre2_compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6466,7 +6466,7 @@ for (;; pptr++)
64666466
/* Now emit the OP_CLASS/OP_NCLASS/OP_XCLASS/OP_ALLANY opcode. */
64676467

64686468
pptr = PRIV(compile_class_not_nested)(options, xoptions, pptr + 1,
6469-
&code, meta == META_CLASS_NOT,
6469+
&code, meta == META_CLASS_NOT, FALSE,
64706470
errorcodeptr, cb, lengthptr);
64716471
if (pptr == NULL) return 0;
64726472
PCRE2_ASSERT(*pptr == META_CLASS_END);

src/pcre2_compile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ void PRIV(update_classbits)(uint32_t ptype, uint32_t pdata, BOOL negated,
263263
OP_CLASS, OP_NCLASS, OP_XCLASS, or OP_ALLANY into pcode. */
264264

265265
uint32_t *PRIV(compile_class_not_nested)(uint32_t options, uint32_t xoptions,
266-
uint32_t *start_ptr, PCRE2_UCHAR **pcode, BOOL negate_class,
266+
uint32_t *start_ptr, PCRE2_UCHAR **pcode, BOOL negate_class, BOOL always_map,
267267
int *errorcodeptr, compile_block *cb, PCRE2_SIZE *lengthptr);
268268

269269
/* Compile the META codes in pptr into opcodes written to pcode. The pptr must

src/pcre2_compile_class.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ become a single OP_CLASS OP_NCLASS, OP_XCLASS, or OP_ALLANY. */
10071007

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

1640-
if ((xclass_props & XCLASS_HAS_8BIT_CHARS) != 0)
1640+
if ((xclass_props & XCLASS_HAS_8BIT_CHARS) != 0 ||
1641+
always_map)
16411642
{
16421643
*code++ |= XCL_MAP;
16431644
(void)memmove(code + (32 / sizeof(PCRE2_UCHAR)), code,
@@ -2079,7 +2080,7 @@ switch (meta)
20792080
prev_ptr = ptr;
20802081
ptr = PRIV(compile_class_not_nested)(options, xoptions, ptr, &code,
20812082
(meta != META_CLASS_NOT) == negated,
2082-
errorcodeptr, cb, lengthptr);
2083+
TRUE, errorcodeptr, cb, lengthptr);
20832084
if (ptr == NULL) return FALSE;
20842085

20852086
/* We must have a 100% guarantee that ptr increases when

src/pcre2_xclass.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,15 @@ const uint8_t *next_char;
7979
utf = TRUE;
8080
#endif
8181

82-
/* Code points < 256 are matched against a bitmap, if one is present. If no
83-
bitmap is present, then the XCLASS does not match any code points < 256. */
84-
85-
if (c < 256)
86-
{
87-
if ((*data & XCL_MAP) != 0)
88-
return (((const uint8_t *)data+1)[c/8] & (1u << (c&7))) != 0;
89-
return FALSE;
90-
}
91-
92-
/* Skip the bitmap. */
82+
/* Code points < 256 are matched against a bitmap, if one is present. */
9383

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

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

0 commit comments

Comments
 (0)