shithub: riscv

Download patch

ref: e880549da638e3fa20465e7ed90d3803aa28fc18
parent: 77d23bae0f7d64ea958c8df410cf029392c6c48c
author: cinap_lenrek <[email protected]>
date: Sat Apr 30 23:03:12 EDT 2016

libregex: fix sed regression (thans spew)

I introduced a regression in sed that currently has screwed up
/sys/lib/man/secindex.

The issue is that sed 's/$/ foo/g' will actually replace the newline
character with foo instead of just appending at the end of the line.
This only makes a difference when sed is operating on a multiple line
record. The effect is a record like:

foo
bar
baz

becomes:

foo foobar foo baz foo

instead of

foo foo
bar foo
baz foo

--- a/sys/src/libregexp/regexec.c
+++ b/sys/src/libregexp/regexec.c
@@ -69,7 +69,6 @@
 			if(r != curinst->r)
 				goto Done;
 		case OANY: /* fallthrough */
-		Any:
 			next = t->next;
 			t->pc = curinst + 1;
 			t->next = nil;
@@ -111,12 +110,10 @@
 			}
 			goto Done;
 		case OEOL:
-			if(r == L'\0' && ep == nil) {
+			if(r == L'\n' || r == L'\0' && ep == nil) {
 				curinst++;
 				goto Again;
 			}
-			if(r == L'\n')
-				goto Any;
 			goto Done;
 		case OJMP:
 			curinst = curinst->a;
--- a/sys/src/libregexp/rregexec.c
+++ b/sys/src/libregexp/rregexec.c
@@ -68,7 +68,6 @@
 			if(*rsp != curinst->r)
 				goto Done;
 		case OANY: /* fallthrough */
-		Any:
 			next = t->next;
 			t->pc = curinst + 1;
 			t->next = nil;
@@ -110,12 +109,10 @@
 			}
 			goto Done;
 		case OEOL:
-			if(*rsp == L'\0' && rep == nil) {
+			if(*rsp == '\n' || *rsp == L'\0' && rep == nil) {
 				curinst++;
 				goto Again;
 			}
-			if(*rsp == '\n')
-				goto Any;
 			goto Done;
 		case OJMP:
 			curinst = curinst->a;