Commit Diff


commit - 1d550471f117b3215fb2b2fd0b873ee6cb77f913
commit + c99ef336aaa39a0c7aa2d0c62e93680764790605
blob - 65944757d6def9f5fa2f82ee1054cb16aef8974c
blob + 3a3e78c536a2927abd48b1d0df3721300d388715
--- src/cmd/acme/regx.c
+++ src/cmd/acme/regx.c
@@ -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;
 
 /*
@@ -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*);
@@ -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;
@@ -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
@@ -610,14 +611,14 @@ rxexecute(Text *t, Rune *r, uint startp, uint eof, Ran
 		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 = */
@@ -626,9 +627,9 @@ rxexecute(Text *t, Rune *r, uint startp, uint eof, Ran
 			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:
@@ -666,9 +667,9 @@ rxexecute(Text *t, Rune *r, uint startp, uint eof, Ran
 				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;
@@ -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 = */
@@ -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:
@@ -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;
blob - 937fb4fe1d6a4d4fab8dfdfa6090be8fbf905c0c
blob + 8beaa036dc1889e0c49f509f543f88132ab0cec6
--- src/cmd/sam/regexp.c
+++ src/cmd/sam/regexp.c
@@ -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;
 
 /*
@@ -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*);
@@ -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;
@@ -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
@@ -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 = */
@@ -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:
@@ -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;
@@ -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 = */
@@ -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:
@@ -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;