From a64e35b336dbca32aa16228b09670ff8f83029d2 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 28 Mar 2015 20:21:03 -0500 Subject: Fix sed bug David Halls hit trying to compile libiconv. --- toys/posix/sed.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'toys/posix/sed.c') diff --git a/toys/posix/sed.c b/toys/posix/sed.c index 705ea7bc..20975320 100644 --- a/toys/posix/sed.c +++ b/toys/posix/sed.c @@ -4,7 +4,7 @@ * * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html * - * TODO: lines > 2G could signed int wrap length counters. Not just getline() + * TODO: lines > 2G could wrap signed int length counters. Not just getline() * but N and s/// USE_SED(NEWTOY(sed, "(version)e*f*inEr[+Er]", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE)) @@ -967,29 +967,35 @@ resume_a: } // Extend allocation to include new string. We use offsets instead of - // pointers so realloc() moving stuff doesn't break things. Do it - // here instead of toybuf so there's no maximum size. + // pointers so realloc() moving stuff doesn't break things. Ok to write + // \n over NUL terminator because call to extend_string() adds it back. if (!corwin->arg1) corwin->arg1 = reg - (char*)corwin; else if ((corwin+1) != (void *)reg) *(reg++) = '\n'; reg = extend_string((void *)&corwin, line, reg - (char *)corwin, end); - line += end; - - // Line continuation? (Two slightly different input methods, -e with - // embedded newline vs -f line by line. Must parse both correctly.) - if (!strchr("btT:", c) && line[-1] == '\\') { - // backslash only matters if we have an odd number of them - for (i = 0; ihit = 256; + break; + } + if (!(reg[-1] = unescape(*line))) reg[-1] = *line; line++; - goto resume_a; - } else corwin->hit = 256; + } } - } + *reg = 0; + } else line += end; // Commands that take no arguments } else if (!strchr("{dDgGhHlnNpPqx=", c)) break; -- cgit v1.2.3