[Issue 5511] std.regex optional capture with no-match cause error

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jan 31 07:09:21 PST 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5511



--- Comment #1 from karasu <himana.karasu at orange.fr> 2011-01-31 07:07:08 PST ---
initializing startIdx and endIdx isn't enough if optional capture with no match
contains sub-capture with match. save matches state before parse parentheses
and restore state if no-match is needed.

in RegexMatch.trymatch, case engine.REparen (line 2397 in v2.051)
replace lines 2404-2405:
                if (!trymatch(pop, pop + len))
                    goto Lnomatch;

by:
                if (!psave)
                {
                    psave = cast(regmatch_t *)alloca(
                        (engine.re_nsub + 1) * regmatch_t.sizeof);
                }
                memcpy(psave, pmatch.ptr,
                        (engine.re_nsub + 1) * regmatch_t.sizeof);
                if (!trymatch(pop, pop + len)) {
                    memcpy(pmatch.ptr, psave,
                            (engine.re_nsub + 1) * regmatch_t.sizeof);
                    goto Lnomatch;
                }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list