Skip to content

Commit 62d4f92

Browse files
author
Zoltan Herczeg
committed
Don't write code during size computation
1 parent c192b8c commit 62d4f92

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/pcre2_compile_class.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,6 +1790,7 @@ compile_class_operand(uint32_t options, uint32_t xoptions, uint32_t **pptr,
17901790
{
17911791
uint32_t *ptr = *pptr;
17921792
PCRE2_UCHAR *code = *pcode;
1793+
PCRE2_UCHAR *code_start = code;
17931794
BOOL first = TRUE;
17941795

17951796
while (TRUE)
@@ -1844,11 +1845,19 @@ while (TRUE)
18441845
/* Join second and subsequent leaves with an OR. */
18451846
if (!first) *code++ = OP_ECLASS_OR;
18461847

1848+
if (lengthptr != NULL)
1849+
{
1850+
*lengthptr += code - code_start;
1851+
code = code_start;
1852+
}
1853+
18471854
first = FALSE;
18481855
}
18491856

18501857
DONE:
18511858
PCRE2_ASSERT(!first); /* Confirm that we found something. */
1859+
PCRE2_ASSERT(lengthptr == NULL ||
1860+
(code == code_start && *pcode == code_start));
18521861

18531862
*pptr = ptr;
18541863
*pcode = code;
@@ -1904,12 +1913,22 @@ while (*ptr >= META_ECLASS_OR && *ptr <= META_ECLASS_SUB)
19041913
return FALSE;
19051914

19061915
/* Convert infix to postfix (RPN). */
1907-
*code++ = op;
1916+
if (lengthptr != NULL)
1917+
(*lengthptr)++;
1918+
else
1919+
*code++ = op;
19081920
}
19091921

1910-
if (negated) *code++ = OP_ECLASS_NOT;
1922+
if (negated)
1923+
{
1924+
if (lengthptr != NULL)
1925+
(*lengthptr)++;
1926+
else
1927+
*code++ = OP_ECLASS_NOT;
1928+
}
19111929

19121930
PCRE2_ASSERT(*ptr == META_CLASS_END);
1931+
PCRE2_ASSERT(lengthptr == NULL || code == *pcode);
19131932

19141933
*pptr = ptr;
19151934
*pcode = code;

0 commit comments

Comments
 (0)