Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-2-0]: src/usr.bin/sed Pullup rev 1.26-1.28 (requested by grant in...



details:   https://anonhg.NetBSD.org/src/rev/1c1e3d1fc380
branches:  netbsd-2-0
changeset: 561363:1c1e3d1fc380
user:      jmc <jmc%NetBSD.org@localhost>
date:      Mon Jun 14 04:18:00 2004 +0000

description:
Pullup rev 1.26-1.28 (requested by grant in ticket #494)

sed(1) fixes for PR#25899, PR#24234, PR#25911

diffstat:

 usr.bin/sed/compile.c |  34 ++++++++++++++++++++++++++++------
 1 files changed, 28 insertions(+), 6 deletions(-)

diffs (76 lines):

diff -r 06d50f6ebb4d -r 1c1e3d1fc380 usr.bin/sed/compile.c
--- a/usr.bin/sed/compile.c     Mon Jun 14 04:16:43 2004 +0000
+++ b/usr.bin/sed/compile.c     Mon Jun 14 04:18:00 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compile.c,v 1.25 2003/08/07 11:15:49 agc Exp $ */
+/*     $NetBSD: compile.c,v 1.25.2.1 2004/06/14 04:18:00 jmc Exp $     */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -72,7 +72,7 @@
 #if 0
 static char sccsid[] = "@(#)compile.c  8.2 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: compile.c,v 1.25 2003/08/07 11:15:49 agc Exp $");
+__RCSID("$NetBSD: compile.c,v 1.25.2.1 2004/06/14 04:18:00 jmc Exp $");
 #endif
 #endif /* not lint */
 
@@ -481,6 +481,7 @@
        static char lbuf[_POSIX2_LINE_MAX + 1];
        int asize, ref, size;
        char c, *text, *op, *sp;
+       int sawesc = 0;
 
        c = *p++;                       /* Terminator character */
        if (c == '\0')
@@ -494,9 +495,29 @@
        do {
                op = sp = text + size;
                for (; *p; p++) {
-                       if (*p == '\\') {
-                               p++;
-                               if (strchr("123456789", *p) != NULL) {
+                       if (*p == '\\' || sawesc) {
+                               /*
+                                * If this is a continuation from the last
+                                * buffer, we won't have a character to
+                                * skip over.
+                                */
+                               if (sawesc)
+                                       sawesc = 0;
+                               else
+                                       p++;
+
+                               if (*p == '\0') {
+                                       /*
+                                        * This escaped character is continued
+                                        * in the next part of the line.  Note
+                                        * this fact, then cause the loop to
+                                        * exit w/ normal EOL case and reenter
+                                        * above with the new buffer.
+                                        */
+                                       sawesc = 1;
+                                       p--;
+                                       continue;
+                               } else if (strchr("123456789", *p) != NULL) {
                                        *sp++ = '\\';
                                        ref = *p - '0';
                                        if (s->re != NULL &&
@@ -570,6 +591,7 @@
                        gn = 1;
                        /* XXX Check for overflow */
                        s->n = (int)strtol(p, &p, 10);
+                       p--;
                        break;
                case 'w':
                        p++;
@@ -634,7 +656,7 @@
                return (NULL);
        }
        /* We assume characters are 8 bits */
-       lt = xmalloc(UCHAR_MAX);
+       lt = xmalloc(UCHAR_MAX+1);
        for (i = 0; i <= UCHAR_MAX; i++)
                lt[i] = (char)i;
        for (op = old, np = new; *op; op++, np++)



Home | Main Index | Thread Index | Old Index