aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/sed.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-01-13 04:28:19 -0600
committerRob Landley <rob@landley.net>2015-01-13 04:28:19 -0600
commit9d66c41d1d2c4ebbd4e7034145bf0143fa5e08b9 (patch)
tree0bd69cb333f90ba544f3a9be4b2dae85bd9b9469 /toys/posix/sed.c
parent3a4917a5bb131fbe358c1c33ca71296774881fe1 (diff)
downloadtoybox-9d66c41d1d2c4ebbd4e7034145bf0143fa5e08b9.tar.gz
sed bugfix: N or n at end of script would save the terminating NULL as the resume position, so the script would restart from beginning.
Diffstat (limited to 'toys/posix/sed.c')
-rw-r--r--toys/posix/sed.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/toys/posix/sed.c b/toys/posix/sed.c
index 438989ec..e35325d3 100644
--- a/toys/posix/sed.c
+++ b/toys/posix/sed.c
@@ -297,7 +297,9 @@ static void walk_pattern(char **pline, long plen)
if (line[len-1] == '\n') line[--len] = eol++;
TT.count++;
- logrus = TT.restart ? TT.restart : (void *)TT.pattern;
+ // The restart-1 is because we added one to make sure it wasn't NULL,
+ // otherwise N as last command would restart script
+ logrus = TT.restart ? ((struct step *)TT.restart)-1 : (void *)TT.pattern;
TT.restart = 0;
while (logrus) {
@@ -452,14 +454,14 @@ static void walk_pattern(char **pline, long plen)
toybuf[off++] = '$';
emit(toybuf, off, 1);
} else if (c=='n') {
- TT.restart = logrus->next;
+ TT.restart = logrus->next+1;
break;
} else if (c=='N') {
// Can't just grab next line because we could have multiple N and
// we need to actually read ahead to get N;$p EOF detection right.
if (pline) {
- TT.restart = logrus->next;
+ TT.restart = logrus->next+1;
extend_string(&line, TT.nextline, len, -TT.nextlen);
free(TT.nextline);
TT.nextline = line;