aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/sed.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-01-22 02:18:30 -0600
committerRob Landley <rob@landley.net>2015-01-22 02:18:30 -0600
commit4bb3a3529704989dd9112baece164b2f51b44e89 (patch)
tree9fa1da25c3e3ad6eb6c73c258516c3c44a60e839 /toys/posix/sed.c
parentef0546d4f536f42a57af4c32bd37f7fd752d10c2 (diff)
downloadtoybox-4bb3a3529704989dd9112baece164b2f51b44e89.tar.gz
Fix sed s//\[newline]/ line continuations.
The problem was that readline() was returning a newline at the end of each string, which wasn't getting stripped in the parser and thus \ wasn't at the end of a line for -f, it was escaping a literal newline, so the continuation logic didn't trigger. Remove some redundant null checks while we're at it, and don't bother terminating a string we don't return (yes we leak memory in an error path, but it's about to error_exit() anyway).
Diffstat (limited to 'toys/posix/sed.c')
-rw-r--r--toys/posix/sed.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/toys/posix/sed.c b/toys/posix/sed.c
index e35325d3..d271c509 100644
--- a/toys/posix/sed.c
+++ b/toys/posix/sed.c
@@ -713,11 +713,7 @@ static char *unescape_delimited_string(char **pstr, char *delim, int regex)
to = delim = xmalloc(strlen(*pstr)+1);
while (mode || *from != d) {
- if (!*from) {
- *to = 0;
-
- return 0;
- }
+ if (!*from) return 0;
// delimiter in regex character range doesn't count
if (*from == '[') {
@@ -737,7 +733,7 @@ static char *unescape_delimited_string(char **pstr, char *delim, int regex)
*(to++) = c;
from+=2;
continue;
- } else if (from[1]) *(to++) = *(from++);
+ } else *(to++) = *(from++);
}
}
*(to++) = *(from++);
@@ -756,6 +752,7 @@ static void jewel_of_judgement(char **pline, long len)
int i;
line = errstart = pline ? *pline : "";
+ if (len && line[len-1]=='\n') line[--len] = 0;
// Append additional line to pattern argument string?
// We temporarily repurpose "hit" to indicate line continuations
@@ -857,7 +854,7 @@ resume_s:
// processing later, after we replace \\ with \ we can't tell \\1 from \1
fiona = line;
while (*fiona != corwin->hit) {
- if (!*fiona) break;
+ if (!*fiona) goto brand;
if (*fiona++ == '\\') {
if (!*fiona || *fiona == '\n') {
fiona[-1] = '\n';