Author: jilles
Date: Sun Apr  2 12:37:43 2017
New Revision: 316414
URL: https://svnweb.freebsd.org/changeset/base/316414

Log:
  sh: Don't scan word twice in ${param+-word}.
  
  There is no longer a case where argbackq has already been advanced but the
  string pointer needs to be advanced.

Modified:
  head/bin/sh/expand.c

Modified: head/bin/sh/expand.c
==============================================================================
--- head/bin/sh/expand.c        Sun Apr  2 11:36:25 2017        (r316413)
+++ head/bin/sh/expand.c        Sun Apr  2 12:37:43 2017        (r316414)
@@ -753,15 +753,14 @@ again: /* jump here after setting a vari
                break;
 
        case VSNORMAL:
-               break;
+               return p;
 
        case VSPLUS:
        case VSMINUS:
                if (!set) {
-                       argstr(p, argbackq,
+                       return argstr(p, argbackq,
                            flag | (flag & EXP_SPLIT ? EXP_SPLIT_LIT : 0) |
                            (varflags & VSQUOTE ? EXP_LIT_QUOTED : 0), dst);
-                       break;
                }
                break;
 
@@ -769,10 +768,8 @@ again: /* jump here after setting a vari
        case VSTRIMLEFTMAX:
        case VSTRIMRIGHT:
        case VSTRIMRIGHTMAX:
-               if (!set) {
-                       set = 1;
+               if (!set)
                        break;
-               }
                /*
                 * Terminate the string and start recording the pattern
                 * right after it
@@ -805,15 +802,14 @@ again: /* jump here after setting a vari
                abort();
        }
 
-       if (subtype != VSNORMAL) {      /* skip to end of alternative */
+       {       /* skip to end of alternative */
                int nesting = 1;
                for (;;) {
                        if ((c = *p++) == CTLESC)
                                p++;
-                       else if (c == CTLBACKQ || c == (CTLBACKQ|CTLQUOTE)) {
-                               if (set)
-                                       *argbackq = (*argbackq)->next;
-                       } else if (c == CTLVAR) {
+                       else if (c == CTLBACKQ || c == (CTLBACKQ|CTLQUOTE))
+                               *argbackq = (*argbackq)->next;
+                       else if (c == CTLVAR) {
                                if ((*p++ & VSTYPE) != VSNORMAL)
                                        nesting++;
                        } else if (c == CTLENDVAR) {
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to