tbetter fix - plan9port - [fork] Plan 9 from user space (HTM) git clone git://src.adamsgaard.dk/plan9port (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit c99ef336aaa39a0c7aa2d0c62e93680764790605 (DIR) parent 1d550471f117b3215fb2b2fd0b873ee6cb77f913 (HTM) Author: rsc <devnull@localhost> Date: Sat, 9 Jun 2007 05:17:47 +0000 better fix Diffstat: M src/cmd/acme/regx.c | 29 +++++++++++++++-------------- M src/cmd/sam/regexp.c | 29 +++++++++++++++-------------- 2 files changed, 30 insertions(+), 28 deletions(-) --- (DIR) diff --git a/src/cmd/acme/regx.c b/src/cmd/acme/regx.c t@@ -49,10 +49,10 @@ struct Ilist uint startp; /* first char of match */ }; -#define NLIST 128 +#define NLIST 127 Ilist *tl, *nl; /* This list, next list */ -Ilist list[2][NLIST]; +Ilist list[2][NLIST+1]; /* +1 for trailing null */ static Rangeset sempty; /* t@@ -109,7 +109,7 @@ int Nclass; /* high water mark */ Rune **class; int negateclass; -void addinst(Ilist *l, Inst *inst, Rangeset *sep); +int addinst(Ilist *l, Inst *inst, Rangeset *sep); void newmatch(Rangeset*); void bnewmatch(Rangeset*); void pushand(Inst*, Inst*); t@@ -525,7 +525,7 @@ classmatch(int classno, int c, int negate) * *l must be pending when addinst called; if *l has been looked * at already, the optimization is a bug. */ -void +int addinst(Ilist *l, Inst *inst, Rangeset *sep) { Ilist *p; t@@ -534,12 +534,13 @@ addinst(Ilist *l, Inst *inst, Rangeset *sep) if(p->inst==inst){ if((sep)->r[0].q0 < p->se.r[0].q0) p->se= *sep; /* this would be bug */ - return; /* It's already there */ + return 0; /* It's already there */ } } p->inst = inst; p->se= *sep; (p+1)->inst = nil; + return 1; } int t@@ -610,14 +611,14 @@ rxexecute(Text *t, Rune *r, uint startp, uint eof, Rangeset *rp) nnl = 0; if(sel.r[0].q0<0 && (!wrapped || p<startp || startp==eof)){ /* Add first instruction to this list */ + sempty.r[0].q0 = p; + if(addinst(tl, startinst, &sempty)) if(++ntl >= NLIST){ Overflow: warning(nil, "regexp list overflow\n"); sel.r[0].q0 = -1; goto Return; } - sempty.r[0].q0 = p; - addinst(tl, startinst, &sempty); } /* Execute machine until this list is empty */ for(tlp = tl; inst = tlp->inst; tlp++){ /* assignment = */ t@@ -626,9 +627,9 @@ rxexecute(Text *t, Rune *r, uint startp, uint eof, Rangeset *rp) default: /* regular character */ if(inst->type==c){ Addinst: + if(addinst(nl, inst->u1.next, &tlp->se)) if(++nnl >= NLIST) goto Overflow; - addinst(nl, inst->u1.next, &tlp->se); } break; case LBRA: t@@ -666,9 +667,9 @@ rxexecute(Text *t, Rune *r, uint startp, uint eof, Rangeset *rp) break; case OR: /* evaluate right choice later */ + if(addinst(tl, inst->u.right, &tlp->se)) if(++ntl >= NLIST) goto Overflow; - addinst(tl, inst->u.right, &tlp->se); /* efficiency: advance and re-evaluate */ inst = inst->u1.left; goto Switchstmt; t@@ -747,15 +748,15 @@ rxbexecute(Text *t, uint startp, Rangeset *rp) nnl = 0; if(sel.r[0].q0<0 && (!wrapped || p>startp)){ /* Add first instruction to this list */ + /* the minus is so the optimizations in addinst work */ + sempty.r[0].q0 = -p; + if(addinst(tl, bstartinst, &sempty)) if(++ntl >= NLIST){ Overflow: warning(nil, "regexp list overflow\n"); sel.r[0].q0 = -1; goto Return; } - /* the minus is so the optimizations in addinst work */ - sempty.r[0].q0 = -p; - addinst(tl, bstartinst, &sempty); } /* Execute machine until this list is empty */ for(tlp = tl; inst = tlp->inst; tlp++){ /* assignment = */ t@@ -764,9 +765,9 @@ rxbexecute(Text *t, uint startp, Rangeset *rp) default: /* regular character */ if(inst->type == c){ Addinst: + if(addinst(nl, inst->u1.next, &tlp->se)) if(++nnl >= NLIST) goto Overflow; - addinst(nl, inst->u1.next, &tlp->se); } break; case LBRA: t@@ -804,9 +805,9 @@ rxbexecute(Text *t, uint startp, Rangeset *rp) break; case OR: /* evaluate right choice later */ + if(addinst(tl, inst->u.right, &tlp->se)) if(++ntl >= NLIST) goto Overflow; - addinst(tlp, inst->u.right, &tlp->se); /* efficiency: advance and re-evaluate */ inst = inst->u1.left; goto Switchstmt; (DIR) diff --git a/src/cmd/sam/regexp.c b/src/cmd/sam/regexp.c t@@ -44,10 +44,10 @@ struct Ilist Posn startp; /* first char of match */ }; -#define NLIST 128 +#define NLIST 127 Ilist *tl, *nl; /* This list, next list */ -Ilist list[2][NLIST]; +Ilist list[2][NLIST+1]; /* +1 for trailing null */ static Rangeset sempty; /* t@@ -104,7 +104,7 @@ int Nclass; /* high water mark */ Rune **class; int negateclass; -void addinst(Ilist *l, Inst *inst, Rangeset *sep); +int addinst(Ilist *l, Inst *inst, Rangeset *sep); void newmatch(Rangeset*); void bnewmatch(Rangeset*); void pushand(Inst*, Inst*); t@@ -531,7 +531,7 @@ classmatch(int classno, int c, int negate) * *l must be pending when addinst called; if *l has been looked * at already, the optimization is a bug. */ -void +int addinst(Ilist *l, Inst *inst, Rangeset *sep) { Ilist *p; t@@ -540,12 +540,13 @@ addinst(Ilist *l, Inst *inst, Rangeset *sep) if(p->inst==inst){ if((sep)->p[0].p1 < p->se.p[0].p1) p->se= *sep; /* this would be bug */ - return; /* It's already there */ + return 0; /* It's already there */ } } p->inst = inst; p->se= *sep; (p+1)->inst = 0; + return 1; } int t@@ -592,11 +593,11 @@ execute(File *f, Posn startp, Posn eof) nnl = 0; if(sel.p[0].p1<0 && (!wrapped || p<startp || startp==eof)){ /* Add first instruction to this list */ + sempty.p[0].p1 = p; + if(addinst(tl, startinst, &sempty)) if(++ntl >= NLIST) Overflow: error(Eoverflow); - sempty.p[0].p1 = p; - addinst(tl, startinst, &sempty); } /* Execute machine until this list is empty */ for(tlp = tl; inst = tlp->inst; tlp++){ /* assignment = */ t@@ -605,9 +606,9 @@ execute(File *f, Posn startp, Posn eof) default: /* regular character */ if(inst->type==c){ Addinst: + if(addinst(nl, inst->next, &tlp->se)) if(++nnl >= NLIST) goto Overflow; - addinst(nl, inst->next, &tlp->se); } break; case LBRA: t@@ -645,9 +646,9 @@ execute(File *f, Posn startp, Posn eof) break; case OR: /* evaluate right choice later */ + if(addinst(tl, inst->right, &tlp->se)) if(++ntl >= NLIST) goto Overflow; - addinst(tl, inst->right, &tlp->se); /* efficiency: advance and re-evaluate */ inst = inst->left; goto Switchstmt; t@@ -717,12 +718,12 @@ bexecute(File *f, Posn startp) nnl = 0; if(sel.p[0].p1<0 && (!wrapped || p>startp)){ /* Add first instruction to this list */ + /* the minus is so the optimizations in addinst work */ + sempty.p[0].p1 = -p; + if(addinst(tl, bstartinst, &sempty)) if(++ntl >= NLIST) Overflow: error(Eoverflow); - /* the minus is so the optimizations in addinst work */ - sempty.p[0].p1 = -p; - addinst(tl, bstartinst, &sempty); } /* Execute machine until this list is empty */ for(tlp = tl; inst = tlp->inst; tlp++){ /* assignment = */ t@@ -731,9 +732,9 @@ bexecute(File *f, Posn startp) default: /* regular character */ if(inst->type == c){ Addinst: + if(addinst(nl, inst->next, &tlp->se)) if(++nnl >= NLIST) goto Overflow; - addinst(nl, inst->next, &tlp->se); } break; case LBRA: t@@ -771,9 +772,9 @@ bexecute(File *f, Posn startp) break; case OR: /* evaluate right choice later */ + if(addinst(tl, inst->right, &tlp->se)) if(++ntl >= NLIST) goto Overflow; - addinst(tlp, inst->right, &tlp->se); /* efficiency: advance and re-evaluate */ inst = inst->left; goto Switchstmt;