about summary refs log tree commit diff
path: root/Src/params.c
diff options
context:
space:
mode:
Diffstat (limited to 'Src/params.c')
-rw-r--r--Src/params.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/Src/params.c b/Src/params.c
index ed8b4a412..14ff4f6ca 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -1276,6 +1276,19 @@ getarg(char **str, int *inv, Value v, int a2, zlong *w,
 			if (pprog && pattry(pprog, *p) && !--num)
 			    return r;
 		    }
+		    /*
+		     * Failed to match.
+		     * If we're returning an index, return 0 to show
+		     * we've gone off the start.  Unfortunately this
+		     * is ambiguous with KSH_ARRAYS set, but we're
+		     * stuck with that now.
+		     *
+		     * If the index is to be turned into an element,
+		     * return an index that does not point to a valid
+		     * element (since 0 is treated the same as 1).
+		     */
+		    if (!ind)
+			r = len + 1;
 		} else
 		    for (r = 1 + beg, p = ta + beg; *p; r++, p++)
 			if (pprog && pattry(pprog, *p) && !--num)
@@ -1495,7 +1508,13 @@ getarg(char **str, int *inv, Value v, int a2, zlong *w,
 		    }
 		}
 	    }
-	    return down ? 0 : slen + 1;
+	    /*
+	     * Failed to match.
+	     * If the argument selects an element rather than
+	     * its index, ensure the element is empty.
+	     * See comments on the array case above.
+	     */
+	    return (down && ind) ? 0 : slen + 1;
 	}
     }
     return r;