summaryrefslogtreecommitdiffstats
path: root/usr.bin/sed/compile.c
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>1996-07-17 12:18:51 +0000
committerbde <bde@FreeBSD.org>1996-07-17 12:18:51 +0000
commit8c325c27d26c5177c6ff268e5ab101ca02858710 (patch)
treee68937593ee3120bbb27a67fb5310f4309cd65c3 /usr.bin/sed/compile.c
parentd2dedce6654e082593b05a4b9dda3d0f6132f1a1 (diff)
downloadFreeBSD-src-8c325c27d26c5177c6ff268e5ab101ca02858710.zip
FreeBSD-src-8c325c27d26c5177c6ff268e5ab101ca02858710.tar.gz
Yet^2 another fix for the line continuation bug.
The fundamental problem with the original code is that it accesses p[-2] which is one before the beginning of the input buffer for empty lines. rev.1.6 just moved the problem from failures when p[-2] happens to be '\\' to failures when it happens to be '\0'. rev.1.5 was confused about the trailing newline and other things. I went back to rev.1.5 and fixed it. The result is the same as Keith Bostic's final version in PR 1356 except it loses more gracefully for excessively long input lines.
Diffstat (limited to 'usr.bin/sed/compile.c')
-rw-r--r--usr.bin/sed/compile.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/usr.bin/sed/compile.c b/usr.bin/sed/compile.c
index 7e11382..c1bb8f9 100644
--- a/usr.bin/sed/compile.c
+++ b/usr.bin/sed/compile.c
@@ -615,7 +615,7 @@ compile_tr(p, transtab)
static char *
compile_text()
{
- int asize, size;
+ int asize, esc_nl, size;
char *text, *p, *op, *s;
char lbuf[_POSIX2_LINE_MAX + 1];
@@ -626,13 +626,13 @@ compile_text()
op = s = text + size;
p = lbuf;
EATSPACE();
- for (; *p != '\0'; p++) {
- if (*p == '\\')
- *p++ = '\0';
+ for (esc_nl = 0; *p != '\0'; p++) {
+ if (*p == '\\' && p[1] != '\0' && *++p == '\n')
+ esc_nl = 1;
*s++ = *p;
}
size += s - op;
- if (p[-2] != '\0') {
+ if (!esc_nl) {
*s = '\0';
break;
}
OpenPOWER on IntegriCloud