# HG changeset patch # User Rob Landley # Date 1421914710 21600 # Node ID e3d20011b68edf368b791623dd66570c9d46a5a3 # Parent 7e3372a4724826d1c86ca85f0fd489718178f98c 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). diff -r 7e3372a47248 -r e3d20011b68e toys/posix/sed.c --- a/toys/posix/sed.c Tue Jan 20 16:03:29 2015 -0600 +++ b/toys/posix/sed.c Thu Jan 22 02:18:30 2015 -0600 @@ -713,11 +713,7 @@ 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 @@ *(to++) = c; from+=2; continue; - } else if (from[1]) *(to++) = *(from++); + } else *(to++) = *(from++); } } *(to++) = *(from++); @@ -756,6 +752,7 @@ 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 @@ // 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';