<i>Regexp backreference fail with a * closure</i> status still Open with 4 other changes
by
.
D 2012-02-14T09:06:37
J icomment I\stried\sto\supload\sthis\sas\sa\spatch,\sbut\sthat\sdidn't\sseem\sto\swork\samazingly\swell,\sso\slet's\ssee\sabout\spasting\sit\sright\sinto\sthe\scomment\sbox\s...\n\n\nThe\sattached\spatch\sfixes\sthe\scase\sof\s"\\n*",\sthat\sis\sa\sbackref\swith\s*\nquantification\sdirectly\sattached\sto\sit.\n\nThe\score\sof\sthe\sproblem\sis\sin\sregcomp.c,\swhich\sfirst\schanges\s"\\n*"\sto\n"\\n+|"\s(lines\s1167ff\sas\sof\s8.5.11)\sand\sthen\sapplies\srepeat()\sto\sthe\sNFA\nrepresenting\sthe\sbackref\satom\s(line\s1198).\s\srepeat()\sthinks\sthat\sany\sarc\nleading\sinto\sits\s"rp"\sargument\sis\spart\sof\sthe\ssub-NFA\sto\sbe\srepeated\s---\nsee\smoveins()\scall\sat\sline\s1363.\s\sUnfortunately,\ssince\sline\s1170\salready\ncreated\sthe\sarc\sthat\swas\sintended\sto\srepresent\sthe\sempty\sbypass\saround\n"\\n+",\sthis\sarc\sgets\smoved\stoo,\sso\sthat\sit\snow\sleads\sinto\sthe\sstate\sloop\ncreated\sby\srepeat().\s\sThus,\swhat\swas\ssupposed\sto\sbe\san\s"empty"\sbypass\sgets\nturned\sinto\ssomething\sthat\srepresents\szero\sor\smore\srepetitions\sof\sthe\sNFA\nrepresenting\sthe\sbackref\satom.\s\sIn\sthe\soriginal\sexample,\sin\splace\sof\n^([bc])\\1*$\nwe\snow\shave\ssomething\sthat\sacts\slike\n^([bc])(\\1+|[bc]*)$\nAt\sruntime,\sthe\sbranch\sinvolving\sthe\sactual\sbackref\sfails,\sas\sit's\ssupposed\nto,\sbut\sthen\sthe\sother\sbranch\ssucceeds\sanyway.\n\nWe\scould\sno\sdoubt\sfix\sthis\sby\ssome\srearrangement\sof\sthe\soperations\sin\nparseqatom(),\sbut\sthat\scode\sis\splenty\sugly\salready.\s\sWhat\sI\spropose\sinstead\nis\sto\sallow\sthe\sm\s==\s0\scase\sto\sbe\shandled\sat\sruntime,\sso\sthat\sthere\sis\sno\nneed\sto\sinstall\sthe\sempty-alternative\sbranch\sat\sall\sfor\sthe\sbackref\scase.\nThis\smakes\sthe\spatch\sin\sregcomp.c\sa\sone-liner,\sat\sthe\scost\sof\shaving\sto\ntweak\scbrdissect()\sa\slittle.\s\sIn\sthe\sattached\spatch\sI\swent\sa\sbit\sfurther\nthan\sthat\sand\srewrote\scbrdissect()\sto\scheck\sall\sthe\sstring-length-related\nconditions\sbefore\sit\sstarts\scomparing\scharacters.\s\sIt\sseems\sa\sbit\sstupid\sto\npossibly\siterate\sthrough\smany\smany\scopies\sof\san\sn-character\sbackreference,\nonly\sto\sfail\sat\sthe\send\sbecause\sthe\starget\sstring's\slength\sisn't\sa\smultiple\nof\sn\s---\swe\scould\shave\sfound\sthat\sout\sbefore\sstarting.\s\sThe\sexisting\scoding\ncould\sonly\sbe\sa\swin\sif\sinteger\sdivision\sis\shugely\sexpensive\scompared\sto\ncharacter\scomparison,\sbut\sI\sdon't\sknow\sof\sany\smodern\smachine\swhere\sthat\nmight\sbe\strue.\n\nThe\spatch\salso\scorrects\san\sobviously\sbogus\scomment\sat\sregexec.c:802.\nPerhaps\sat\sone\stime\sit\swas\svalid,\sbut\snow\sthis\sis\sthe\sonly\scaller\sof\ncbrdissect()\s...\n\nThis\sdoes\snot\sfix\sall\sthe\sproblems\swith\squantified\sback-references.\s\sIn\nparticular,\sthe\scode\sis\scompletely\sbroken\sfor\sback-references\sthat\sappear\nwithin\sa\slarger\sexpression\sthat\sis\squantified,\sso\sseveral\sof\sthe\scases\nshown\sin\sthe\scomments\sto\sthis\sbug\sentry\sstill\sdon't\swork.\s\sI\sdo\snot\shave\na\ssolution\sfor\sthat\syet;\sit\slooks\sto\sme\slike\sit\smay\srequire\smajor\ssurgery.\nHowever,\sthe\schanges\sI\spropose\snow\sseem\sappropriate\sto\smake\sanyway.\s\sDoing\ndirect\shandling\sof\squantification\sin\sa\ssimple\sback-ref\sis\sa\sperformance\swin\ncompared\sto\sanything\swe\scan\spossibly\sdo\sat\sa\shigher\slevel,\sso\sthis\scode\npath\sseems\sworth\spreserving\seven\sif\swe\sneed\sanother\ssolution\sfor\sthe\smore\ngeneral\scase.\n\n\ndiff\s-cr\stcl8.5.11.orig/generic/regcomp.c\stcl8.5.11/generic/regcomp.c\n***\stcl8.5.11.orig/generic/regcomp.cTue\sNov\s\s1\s10:04:51\s2011\n---\stcl8.5.11/generic/regcomp.cMon\sFeb\s13\s16:03:05\s2012\n***************\n***\s1161,1170\s****\n\s\s\s\s\s\s}\n\s\s\n\s\s\s\s\s\s/*\n!\s\s\s\s\s\s*\sIt's\squantifier\stime;\sfirst,\sturn\sx{0,...}\sinto\sx{1,...}|empty\n\s\s\s\s\s\s\s*/\n\s\s\n!\s\s\s\s\sif\s(m\s==\s0)\s{\n\s\sEMPTYARC(s2,\satom->end);/*\sthe\sbypass\s*/\n\s\sassert(PREF(qprefer)\s!=\s0);\n\s\sf\s=\sCOMBINE(qprefer,\satom->flags);\n---\s1161,1172\s----\n\s\s\s\s\s\s}\n\s\s\n\s\s\s\s\s\s/*\n!\s\s\s\s\s\s*\sIt's\squantifier\stime.\s\sIf\sthe\satom\sis\sjust\sa\sBACKREF,\swe'll\slet\sit\sdeal\n!\s\s\s\s\s\s*\swith\squantifiers\sinternally.\s\sOtherwise,\sthe\sfirst\sstep\sis\sto\sturn\n!\s\s\s\s\s\s*\sx{0,...}\sinto\sx{1,...}|empty\n\s\s\s\s\s\s\s*/\n\s\s\n!\s\s\s\s\sif\s(m\s==\s0\s&&\satomtype\s!=\sBACKREF)\s{\n\s\sEMPTYARC(s2,\satom->end);/*\sthe\sbypass\s*/\n\s\sassert(PREF(qprefer)\s!=\s0);\n\s\sf\s=\sCOMBINE(qprefer,\satom->flags);\ndiff\s-cr\stcl8.5.11.orig/generic/regexec.c\stcl8.5.11/generic/regexec.c\n***\stcl8.5.11.orig/generic/regexec.cTue\sNov\s\s1\s10:04:51\s2011\n---\stcl8.5.11/generic/regexec.cMon\sFeb\s13\s16:03:11\s2012\n***************\n***\s799,805\s****\n\s\s\s\s\s\scase\s'|':/*\salternation\s*/\n\s\sassert(t->left\s!=\sNULL);\n\s\sreturn\scaltdissect(v,\st,\sbegin,\send);\n!\s\s\s\s\scase\s'b':/*\sback\sref\s--\sshouldn't\sbe\scalling\sus!\s*/\n\s\sassert(t->left\s==\sNULL\s&&\st->right\s==\sNULL);\n\s\sreturn\scbrdissect(v,\st,\sbegin,\send);\n\s\s\s\s\s\scase\s'.':/*\sconcatenation\s*/\n---\s799,805\s----\n\s\s\s\s\s\scase\s'|':/*\salternation\s*/\n\s\sassert(t->left\s!=\sNULL);\n\s\sreturn\scaltdissect(v,\st,\sbegin,\send);\n!\s\s\s\s\scase\s'b':/*\sback\sreference\s*/\n\s\sassert(t->left\s==\sNULL\s&&\st->right\s==\sNULL);\n\s\sreturn\scbrdissect(v,\st,\sbegin,\send);\n\s\s\s\s\s\scase\s'.':/*\sconcatenation\s*/\n***************\n***\s1065,1076\s****\n\s\s\s\s\s\schr\s*begin,/*\sbeginning\sof\srelevant\ssubstring\s*/\n\s\s\s\s\s\schr\s*end)/*\send\sof\ssame\s*/\n\s\s{\n-\s\s\s\s\sint\si;\n\s\s\s\s\s\sint\sn\s=\st->subno;\n!\s\s\s\s\ssize_t\slen;\n!\s\s\s\s\schr\s*paren;\n\s\s\s\s\s\schr\s*p;\n-\s\s\s\s\schr\s*stop;\n\s\s\s\s\s\sint\smin\s=\st->min;\n\s\s\s\s\s\sint\smax\s=\st->max;\n\s\s\n---\s1065,1076\s----\n\s\s\s\s\s\schr\s*begin,/*\sbeginning\sof\srelevant\ssubstring\s*/\n\s\s\s\s\s\schr\s*end)/*\send\sof\ssame\s*/\n\s\s{\n\s\s\s\s\s\sint\sn\s=\st->subno;\n!\s\s\s\s\ssize_t\snumreps;\n!\s\s\s\s\ssize_t\stlen;\n!\s\s\s\s\ssize_t\sbrlen;\n!\s\s\s\s\schr\s*brstring;\n\s\s\s\s\s\schr\s*p;\n\s\s\s\s\s\sint\smin\s=\st->min;\n\s\s\s\s\s\sint\smax\s=\st->max;\n\s\s\n***************\n***\s1081,1091\s****\n\s\s\n\s\s\s\s\s\sMDEBUG(("cbackref\sn%d\s%d{%d-%d}\\n",\st->retry,\sn,\smin,\smax));\n\s\s\n\s\s\s\s\s\sif\s(v->pmatch[n].rm_so\s==\s-1)\s{\n\s\sreturn\sREG_NOMATCH;\n\s\s\s\s\s\s}\n!\s\s\s\s\sparen\s=\sv->start\s+\sv->pmatch[n].rm_so;\n!\s\s\s\s\slen\s=\sv->pmatch[n].rm_eo\s-\sv->pmatch[n].rm_so;\n\s\s\n\s\s\s\s\s\s/*\n\s\s\s\s\s\s\s*\sNo\sroom\sto\smaneuver\s--\sretries\sare\spointless.\n---\s1081,1092\s----\n\s\s\n\s\s\s\s\s\sMDEBUG(("cbackref\sn%d\s%d{%d-%d}\\n",\st->retry,\sn,\smin,\smax));\n\s\s\n+\s\s\s\s\s/*\sGet\sthe\sbackreferenced\sstring\s*/\n\s\s\s\s\s\sif\s(v->pmatch[n].rm_so\s==\s-1)\s{\n\s\sreturn\sREG_NOMATCH;\n\s\s\s\s\s\s}\n!\s\s\s\s\sbrstring\s=\sv->start\s+\sv->pmatch[n].rm_so;\n!\s\s\s\s\sbrlen\s=\sv->pmatch[n].rm_eo\s-\sv->pmatch[n].rm_so;\n\s\s\n\s\s\s\s\s\s/*\n\s\s\s\s\s\s\s*\sNo\sroom\sto\smaneuver\s--\sretries\sare\spointless.\n***************\n***\s1096,1146\s****\n\s\s\s\s\s\s}\n\s\s\s\s\s\sv->mem[t->retry]\s=\s1;\n\s\s\n!\s\s\s\s\s/*\n!\s\s\s\s\s\s*\sSpecial-case\szero-length\sstring.\n!\s\s\s\s\s\s*/\n!\s\n!\s\s\s\s\sif\s(len\s==\s0)\s{\n!\sif\s(begin\s==\send)\s{\n\s\s\s\s\s\sreturn\sREG_OKAY;\n\s\s}\n\s\sreturn\sREG_NOMATCH;\n\s\s\s\s\s\s}\n!\s\n!\s\s\s\s\s/*\n!\s\s\s\s\s\s*\sAnd\stoo-short\sstring.\n!\s\s\s\s\s\s*/\n!\s\n!\s\s\s\s\sassert(end\s>=\sbegin);\n!\s\s\s\s\sif\s((size_t)(end\s-\sbegin)\s<\slen)\s{\n\s\sreturn\sREG_NOMATCH;\n\s\s\s\s\s\s}\n-\s\s\s\s\sstop\s=\send\s-\slen;\n\s\s\n\s\s\s\s\s\s/*\n!\s\s\s\s\s\s*\sCount\soccurrences.\n\s\s\s\s\s\s\s*/\n\s\s\n!\s\s\s\s\si\s=\s0;\n!\s\s\s\s\sfor\s(p\s=\sbegin;\sp\s<=\sstop\s&&\s(i\s<\smax\s||\smax\s==\sINFINITY);\sp\s+=\slen)\s{\n!\sif\s((*v->g->compare)(paren,\sp,\slen)\s!=\s0)\s{\n!\s\s\s\s\sbreak;\n!\s}\n!\si++;\n\s\s\s\s\s\s}\n-\s\s\s\s\sMDEBUG(("cbackref\sfound\s%d\\n",\si));\n-\s\n-\s\s\s\s\s/*\n-\s\s\s\s\s\s*\sAnd\ssort\sit\sout.\n-\s\s\s\s\s\s*/\n\s\s\n!\s\s\s\s\sif\s(p\s!=\send)\s{/*\sdidn't\sconsume\sall\sof\sit\s*/\n!\sreturn\sREG_NOMATCH;\n!\s\s\s\s\s}\n!\s\s\s\s\sif\s(min\s<=\si\s&&\s(i\s<=\smax\s||\smax\s==\sINFINITY))\s{\n!\sreturn\sREG_OKAY;\n!\s\s\s\s\s}\n!\s\s\s\s\sreturn\sREG_NOMATCH;/*\sout\sof\srange\s*/\n\s\s}\n\s\s\n\s\s/*\n---\s1097,1145\s----\n\s\s\s\s\s\s}\n\s\s\s\s\s\sv->mem[t->retry]\s=\s1;\n\s\s\n!\s\s\s\s\s/*\sSpecial\scases\sfor\szero-length\sstrings\s*/\n!\s\s\s\s\sif\s(brlen\s==\s0)\s{\n!\s/*\n!\s\s*\sMatches\sonly\sif\starget\sis\szero\slength,\sbut\sany\snumber\sof\n!\s\s*\srepetitions\scan\sbe\sconsidered\sto\sbe\spresent\n!\s\s*/\n!\sif\s(begin\s==\send\s&&\smin\s<=\smax)\s{\n!\s\s\s\s\sMDEBUG(("cbackref\smatched\strivially\\n"));\n\s\s\s\s\s\sreturn\sREG_OKAY;\n\s\s}\n\s\sreturn\sREG_NOMATCH;\n\s\s\s\s\s\s}\n!\s\s\s\s\sif\s(begin\s==\send)\s{\n!\s/*\sMatches\sonly\sif\szero\srepetitions\sare\sokay\s*/\n!\sif\s(min\s==\s0)\s{\n!\s\s\s\s\sMDEBUG(("cbackref\smatched\strivially\\n"));\n!\s\s\s\s\sreturn\sREG_OKAY;\n!\s}\n\s\sreturn\sREG_NOMATCH;\n\s\s\s\s\s\s}\n\s\s\n\s\s\s\s\s\s/*\n!\s\s\s\s\s\s*\sCheck\starget\slength\sto\ssee\sif\sit\scould\spossibly\sbe\san\sallowed\snumber\sof\n!\s\s\s\s\s\s*\srepetitions\sof\sbrstring\n\s\s\s\s\s\s\s*/\n+\s\s\s\s\sassert(end\s>\sbegin);\n+\s\s\s\s\stlen\s=\send\s-\sbegin;\n+\s\s\s\s\sif\s(tlen\s%\sbrlen\s!=\s0)\n+\sreturn\sREG_NOMATCH;\n+\s\s\s\s\snumreps\s=\stlen\s/\sbrlen;\n+\s\s\s\s\sif\s(numreps\s<\smin\s||\s(numreps\s>\smax\s&&\smax\s!=\sINFINITY))\n+\sreturn\sREG_NOMATCH;\n\s\s\n!\s\s\s\s\s/*\sOkay,\scompare\sthe\sactual\sstring\scontents\s*/\n!\s\s\s\s\sp\s=\sbegin;\n!\s\s\s\s\swhile\s(numreps--\s>\s0)\s{\n!\sif\s((*v->g->compare)\s(brstring,\sp,\sbrlen)\s!=\s0)\n!\s\s\s\s\sreturn\sREG_NOMATCH;\n!\sp\s+=\sbrlen;\n\s\s\s\s\s\s}\n\s\s\n!\s\s\s\s\sMDEBUG(("cbackref\smatched\\n"));\n!\s\s\s\s\sreturn\sREG_OKAY;\n\s\s}\n\s\s\n\s\s/*\n\n
J login tgl
J mimetype text/plain
J username tgl
K 1115587fffffffffffffffffffffffffffffffff
U tgl
Z 907abd38b0a0389a9905c5e2e8bbf5e5