On Thursday, June 16, 2022 at 11:09:34 AM UTC+2, heinrichmartin wrote:
> It looks like Expect has issue generating the glob-gate for that regexp.
> no core dump:
> expect -re {(?x)^
> (foo|bar)
> [\r\n]+?
> }
> core dump:
> expect -re {(?x)^
> (foo)
> [\r\n]+?
> }
>
> Does anyone have an idea/hint?
Actually, I have made huge progress by just writing it down for c.l.t. ... and I am answering my own question now:
The difference is (obviously) the branch "|". Expect stops generating glob-gate when a branch is discovered (retglob.c:236:/* branching is too complex */ goto error).
At this point, I have two possible workarounds: (1) do not use expanded syntax for simple regexp or (2) add a bogus branch, e.g. "(?:a|a)" for "a" or in this case "(?:\r|\n)" for "[\r\n]".
Then, I assume the issue is in retglob.c:223:
if (expanded) {
/* Expanded syntax, whitespace and comments, ignore. */
while (MATCHC (' ') ||
MATCHC (0x9) ||
MATCHC (0xa)) CHOP (1);
/* XXX not checking strlen before proceeding */
if (MATCHC ('#')) {
CHOPC (0xa);
if (strlen) CHOP (1);
continue;
}
}
The tight while-loop is safe, iff the string is \0-terminated, but afterwards: if (0 == strlen) break;
Given that I have a simple workaround, I am going to skip fix+build+verify+deploy and will work with simple syntax instead. If comments are needed, one could assemble and document the regexp in a variable before the actual expect.
HTH
Martin