aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2014-11-16 14:21:42 -0600
committerRob Landley <rob@landley.net>2014-11-16 14:21:42 -0600
commit7928b0d28b7e8fe8b7cb7eeb5ddde4d4840db9e4 (patch)
tree7b677aea3ba069e4749e51b3d73e500460aa754e
parent2814e457ed53f14bc333c79beaa19741a35f1d82 (diff)
downloadtoybox-7928b0d28b7e8fe8b7cb7eeb5ddde4d4840db9e4.tar.gz
Fix sed 'b' with no label and 'N' in general.
-rw-r--r--toys/pending/sed.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/toys/pending/sed.c b/toys/pending/sed.c
index d7987366..7a9500c4 100644
--- a/toys/pending/sed.c
+++ b/toys/pending/sed.c
@@ -3,6 +3,9 @@
* Copyright 2014 Rob Landley <rob@landley.net>
*
* See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html
+ *
+ * TODO: lines > 2G could signed int wrap length counters. Not just getline()
+ * but N and s///
USE_SED(NEWTOY(sed, "(version)e*f*inr", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE))
@@ -335,10 +338,8 @@ static void walk_pattern(char **pline, long plen)
if (c != 'b') tea = 0;
if (c=='b' || t^(c=='T')) {
+ if (!logrus->arg1) break;
str = logrus->arg1+(char *)logrus;
-
-
- if (!*str) break;
for (logrus = (void *)TT.pattern; logrus; logrus = logrus->next)
if (logrus->c == ':' && !strcmp(logrus->arg1+(char *)logrus, str))
break;
@@ -388,14 +389,18 @@ static void walk_pattern(char **pline, long plen)
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;
- extend_string(&line, TT.nextline, plen, -TT.nextlen);
+ extend_string(&line, TT.nextline, len, -TT.nextlen);
free(TT.nextline);
TT.nextline = line;
+ TT.nextlen += len + 1;
line = 0;
}
+ // Pending append goes out right after N
goto done;
} else if (c=='p') {
if (emit(line, len, eol)) break;