From 251be88968c12a2fb8689564f93f330b23a36fd5 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Thu, 7 Sep 2023 03:48:54 -0500 Subject: [PATCH] Use 64 bit comparisons. --- tests/expr.test | 7 +++---- toys/pending/expr.c | 3 +-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/expr.test b/tests/expr.test index da3feea1..d5e1acf9 100755 --- a/tests/expr.test +++ b/tests/expr.test @@ -18,6 +18,7 @@ testing "% * same priority" "expr 3 % 2 \* 4" "4\n" "" "" testing "* % same priority" "expr 3 \* 2 % 4" "2\n" "" "" testing "= > same priority" "expr 0 = 2 \> 3" "0\n" "" "" testing "> = same priority" "expr 3 \> 2 = 1" "1\n" "" "" +testing "64 bit comparison" "expr 100000000000 \> 1" "1\n" "" "" testing "00 | 1" "expr 00 \| 1" "1\n" "" "" testing "-0 | 1" "expr -0 \| 2" "2\n" "" "" @@ -31,8 +32,7 @@ testing "regex no match" "expr ab21xx : x" "0\n" "" "" testing "long str" "expr abcdefghijklmnopqrstuvwxyz : '\(.*\)' = a" "0\n" "" "" # result of ':' regex match can subsequently be used for arithmetic -testing "string becomes integer" "expr ab21xx : '[^0-9]*\([0-9]*\)' + 3" \ - "24\n" "" "" +testing "str becomes int" "expr ab21xx : '[^0-9]*\([0-9]*\)' + 3" "24\n" "" "" testing "integer comparison" "expr -3 \< -2" "1\n" "" "" testing "string comparison" "expr -3 \< -2s" "0\n" "" "" @@ -44,8 +44,7 @@ testing "parens around literal" "expr \( a \)" "a\n" "" "" testing "exit code when true" "expr a; echo \$?" "a\n0\n" "" "" testing "exit code when false" "expr 0; echo \$?" "0\n1\n" "" "" -testing "exit code with syntax error" "expr \( 2>/dev/null; echo \$?" \ - "2\n" "" "" +testing "exit code with syntax err" "expr \( 2>/dev/null; echo \$?" "2\n" "" "" testing "exit code when evaluating to 0" "expr -1 + 1; echo \$?" "0\n1\n" "" "" # BUG: segfaults because '3' is coerced to integer and regexc gets NULL diff --git a/toys/pending/expr.c b/toys/pending/expr.c index a236aaab..54ebd14b 100644 --- a/toys/pending/expr.c +++ b/toys/pending/expr.c @@ -146,9 +146,8 @@ static struct op_def { void eval_op(struct op_def *o, struct value *ret, struct value *rhs) { - long long a, b, x = 0; // x = a OP b for ints. + long long cmp, a, b, x = 0; // x = a OP b for ints. char *s, *t; // string operands - int cmp; switch (o->sig) { -- 2.39.2