Source-Changes-HG archive

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

[src/netbsd-9]: src/bin/sh Pull up following revision(s) (requested by kre in...



details:   https://anonhg.NetBSD.org/src/rev/fa17492e23dc
branches:  netbsd-9
changeset: 934209:fa17492e23dc
user:      martin <martin%NetBSD.org@localhost>
date:      Sun Jun 07 12:50:17 2020 +0000

description:
Pull up following revision(s) (requested by kre in ticket #940):

        bin/sh/expand.h: revision 1.25
        bin/sh/expand.c: revision 1.134
        bin/sh/expand.c: revision 1.135
        bin/sh/expand.c: revision 1.136
        bin/sh/expand.c: revision 1.137

Remove a (completely harmless) duplicate assignment introduced in a
code merge from FreeBSD in 2017.   NFC.

Pointed out by Roland Illig.

prevent sign extension from making expression always false.
remove masking and cast (requested by kre@)

When expanding a here-doc (NXHERE - the type with an unquoted end delim)
the output will not be further processed (at all) so there is no need
to escape magic chars in the output, and doing so leaves stray CTLESC
chars in the here doc text.  Not good.   So don't do that...

To save a strlen() of the result, to determine the size of the here doc,
make rmescapes() return the length of the resulting string (this isn't
needed for other uses, so didn't happen previously).

Reported on current-users@ (2020-02-06) by Jun Ebihara

XXX pullup -9

diffstat:

 bin/sh/expand.c |  23 ++++++++++++++---------
 bin/sh/expand.h |   4 ++--
 2 files changed, 16 insertions(+), 11 deletions(-)

diffs (111 lines):

diff -r 92efbdc19b32 -r fa17492e23dc bin/sh/expand.c
--- a/bin/sh/expand.c   Sun Jun 07 12:35:01 2020 +0000
+++ b/bin/sh/expand.c   Sun Jun 07 12:50:17 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: expand.c,v 1.132.2.1 2019/11/24 08:24:06 martin Exp $  */
+/*     $NetBSD: expand.c,v 1.132.2.2 2020/06/07 12:50:17 martin Exp $  */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)expand.c   8.5 (Berkeley) 5/15/95";
 #else
-__RCSID("$NetBSD: expand.c,v 1.132.2.1 2019/11/24 08:24:06 martin Exp $");
+__RCSID("$NetBSD: expand.c,v 1.132.2.2 2020/06/07 12:50:17 martin Exp $");
 #endif
 #endif /* not lint */
 
@@ -146,10 +146,12 @@
 void
 expandhere(union node *arg, int fd)
 {
+       int len;
 
        herefd = fd;
        expandarg(arg, NULL, 0);
-       xwrite(fd, stackblock(), expdest - stackblock());
+       len = rmescapes(stackblock());
+       xwrite(fd, stackblock(),  len);
 }
 
 
@@ -268,12 +270,12 @@
                        return p - 1;
                case CTLENDVAR: /* end of expanding yyy in ${xxx-yyy} */
                case CTLENDARI: /* end of a $(( )) string */
-                       if (had_dol_at && (*p&0xFF) == CTLQUOTEEND)
+                       if (had_dol_at && *p == CTLQUOTEEND)
                                p++;
                        NULLTERM_4_TRACE(expdest);
                        VTRACE(DBG_EXPAND, ("argstr returning at \"%.6s\"..."
                            " after %2.2X; added \"%s\" to expdest\n",
-                           p, (c&0xff), stackblock()));
+                           p, (c & 0xff), stackblock()));
                        return p;
                case CTLQUOTEMARK:
                        /* "$@" syntax adherence hack */
@@ -307,7 +309,7 @@
                        had_dol_at = 0;
                        break;
                case CTLESC:
-                       if (quotes || ISCTL(*p))
+                       if ((quotes || ISCTL(*p)))
                                STPUTC(c, expdest);
                        c = *p++;
                        STPUTC(c, expdest);
@@ -1955,7 +1957,6 @@
                        }
                        /* end shortcut */
 
-                       invert = 0;
                        savep = p, saveq = q;
                        invert = 0;
                        if (*p == '!' || *p == '^') {
@@ -2038,9 +2039,11 @@
 
 /*
  * Remove any CTLESC or CTLNONL characters from a string.
+ *
+ * String is modified in place, and we return the length of the result
  */
 
-void
+int
 rmescapes(char *str)
 {
        char *p, *q;
@@ -2048,7 +2051,7 @@
        p = str;
        while (!ISCTL(*p)) {
                if (*p++ == '\0')
-                       return;
+                       return ((int)(p - str) - 1);
        }
        q = p;
        while (*p) {
@@ -2070,6 +2073,8 @@
                *q++ = *p++;
        }
        *q = '\0';
+
+       return ((int)(q - str));
 }
 
 /*
diff -r 92efbdc19b32 -r fa17492e23dc bin/sh/expand.h
--- a/bin/sh/expand.h   Sun Jun 07 12:35:01 2020 +0000
+++ b/bin/sh/expand.h   Sun Jun 07 12:50:17 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: expand.h,v 1.24 2018/11/18 17:23:37 kre Exp $  */
+/*     $NetBSD: expand.h,v 1.24.2.1 2020/06/07 12:50:17 martin Exp $   */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -67,5 +67,5 @@
 
 void expandhere(union node *, int);
 void expandarg(union node *, struct arglist *, int);
-void rmescapes(char *);
+int rmescapes(char *);
 int casematch(union node *, char *);



Home | Main Index | Thread Index | Old Index