if (r == NULL)
return NULL;
r->re_in_use = FALSE;
+#ifdef DEBUG
+ r->regsz = regsize;
+#endif
// Second pass: emit code.
regcomp_start(expr, re_flags);
s = r->program + 1;
// Loop until we find the END that isn't before a referred next (an END
// can also appear in a NOMATCH operand).
- while (op != END || s <= end)
+ while ((op != END || s <= end) && s < r->program + r->regsz)
{
op = OP(s);
fprintf(f, "%2d%s", (int)(s - r->program), regprop(s)); // Where, what.
- next = regnext(s);
+ next = (s + 3 <= r->program + r->regsz) ? regnext(s) : NULL;
if (next == NULL) // Next ptr.
fprintf(f, "(0)");
else
s += 5;
}
s += 3;
+ if (op == MULTIBYTECODE)
+ {
+ fprintf(f, " mbc=%d", utf_ptr2char(s));
+ s += utfc_ptr2len(s);
+ }
if (op == ANYOF || op == ANYOF + ADD_NL
|| op == ANYBUT || op == ANYBUT + ADD_NL
|| op == EXACTLY)
{
// Literal string, where present.
fprintf(f, "\nxxxxxxxxx\n");
- while (*s != NUL)
- fprintf(f, "%c", *s++);
+ while (*s != NUL && s < r->program + r->regsz)
+ {
+ fprintf(f, "%c", *s);
+ s += utfc_ptr2len(s); // advance by full char including combining
+ }
fprintf(f, "\nxxxxxxxxx\n");
s++;
}