summaryrefslogtreecommitdiff
path: root/test.c
diff options
context:
space:
mode:
authorChet Ramey <chet.ramey@case.edu>2019-01-07 09:27:52 -0500
committerChet Ramey <chet.ramey@case.edu>2019-01-07 09:27:52 -0500
commitd233b485e83c3a784b803fb894280773f16f2deb (patch)
tree16d51f3ccca2d4ad2d8f2da564d68ca848de595b /test.c
parent64447609994bfddeef1061948022c074093e9a9f (diff)
downloadbash-d233b485e83c3a784b803fb894280773f16f2deb.tar.gz
bash-5.0 distribution sources and documentationbash-5.0
Diffstat (limited to 'test.c')
-rw-r--r--test.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/test.c b/test.c
index ee634204..4cb3343c 100644
--- a/test.c
+++ b/test.c
@@ -274,7 +274,7 @@ term ()
value = binary_operator ();
/* Might be a switch type argument */
- else if (argv[pos][0] == '-' && argv[pos][2] == '\0')
+ else if (argv[pos][0] == '-' && argv[pos][1] && argv[pos][2] == '\0')
{
if (test_unop (argv[pos]))
value = unary_operator ();
@@ -344,10 +344,10 @@ arithcomp (s, t, op, flags)
if (flags & TEST_ARITHEXP)
{
- l = evalexp (s, &expok);
+ l = evalexp (s, 0, &expok);
if (expok == 0)
return (FALSE); /* should probably longjmp here */
- r = evalexp (t, &expok);
+ r = evalexp (t, 0, &expok);
if (expok == 0)
return (FALSE); /* ditto */
}
@@ -622,15 +622,19 @@ unary_test (op, arg)
return (minus_o_option_value (arg) == 1);
case 'v':
- v = find_variable (arg);
#if defined (ARRAY_VARS)
- if (v == 0 && valid_array_reference (arg, 0))
+ if (valid_array_reference (arg, 0))
{
char *t;
- t = array_value (arg, 0, 0, (int *)0, (arrayind_t *)0);
- return (t ? TRUE : FALSE);
+ int rtype, ret;
+ t = array_value (arg, 0, 0, &rtype, (arrayind_t *)0);
+ ret = t ? TRUE : FALSE;
+ if (rtype > 0) /* subscript is * or @ */
+ free (t);
+ return ret;
}
- else if (v && invisible_p (v) == 0 && array_p (v))
+ v = find_variable (arg);
+ if (v && invisible_p (v) == 0 && array_p (v))
{
char *t;
/* [[ -v foo ]] == [[ -v foo[0] ]] */
@@ -643,6 +647,8 @@ unary_test (op, arg)
t = assoc_reference (assoc_cell (v), "0");
return (t ? TRUE : FALSE);
}
+#else
+ v = find_variable (arg);
#endif
return (v && invisible_p (v) == 0 && var_isset (v) ? TRUE : FALSE);
@@ -670,7 +676,7 @@ test_binop (op)
else if (op[2] == '\0' && op[1] == '~' && (op[0] == '=' || op[0] == '!'))
return (1);
#endif
- else if (op[0] != '-' || op[2] == '\0' || op[3] != '\0')
+ else if (op[0] != '-' || op[1] == '\0' || op[2] == '\0' || op[3] != '\0')
return (0);
else
{
@@ -714,7 +720,7 @@ int
test_unop (op)
char *op;
{
- if (op[0] != '-' || op[2] != 0)
+ if (op[0] != '-' || (op[1] && op[2] != 0))
return (0);
switch (op[1])
@@ -736,7 +742,7 @@ two_arguments ()
{
if (argv[pos][0] == '!' && argv[pos][1] == '\0')
return (argv[pos + 1][0] == '\0');
- else if (argv[pos][0] == '-' && argv[pos][2] == '\0')
+ else if (argv[pos][0] == '-' && argv[pos][1] && argv[pos][2] == '\0')
{
if (test_unop (argv[pos]))
return (unary_operator ());
@@ -749,7 +755,7 @@ two_arguments ()
return (0);
}
-#define ANDOR(s) (s[0] == '-' && !s[2] && (s[1] == 'a' || s[1] == 'o'))
+#define ANDOR(s) (s[0] == '-' && (s[1] == 'a' || s[1] == 'o') && s[2] == 0)
/* This could be augmented to handle `-t' as equivalent to `-t 1', but
POSIX requires that `-t' be given an argument. */