From 9d66c41d1d2c4ebbd4e7034145bf0143fa5e08b9 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 13 Jan 2015 04:28:19 -0600 Subject: 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. --- toys/posix/sed.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'toys/posix/sed.c') 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; -- cgit v1.2.3