summaryrefslogtreecommitdiff
path: root/shell/ash_test/ash-arith
diff options
context:
space:
mode:
authorDenys Vlasenko2023-06-25 17:42:05 +0200
committerDenys Vlasenko2023-06-25 17:42:05 +0200
commitc1c267fd36b0fcac8c8871232eecc1e360173990 (patch)
tree83a490c0098926b5e5ef66f474c2b8a6dcfd6620 /shell/ash_test/ash-arith
parent019dd31150526b7dd9dd0addfc38f08bcf7ec551 (diff)
downloadbusybox-c1c267fd36b0fcac8c8871232eecc1e360173990.zip
busybox-c1c267fd36b0fcac8c8871232eecc1e360173990.tar.gz
shell/math: bash-compatible handling of too large numbers
function old new delta parse_with_base - 170 +170 evaluate_string 1477 1309 -168 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/1 up/down: 170/-168) Total: 2 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/ash_test/ash-arith')
-rw-r--r--shell/ash_test/ash-arith/arith-bignum1.right13
-rwxr-xr-xshell/ash_test/ash-arith/arith-bignum1.tests17
-rw-r--r--shell/ash_test/ash-arith/arith.right3
-rwxr-xr-xshell/ash_test/ash-arith/arith.tests6
4 files changed, 35 insertions, 4 deletions
diff --git a/shell/ash_test/ash-arith/arith-bignum1.right b/shell/ash_test/ash-arith/arith-bignum1.right
new file mode 100644
index 0000000..42a8016
--- /dev/null
+++ b/shell/ash_test/ash-arith/arith-bignum1.right
@@ -0,0 +1,13 @@
+18 digits: 999999999999999999
+19 digits: -8446744073709551617
+20 digits: 7766279631452241919
+18 digits- -999999999999999999
+19 digits- 8446744073709551617
+20 digits- -7766279631452241919
+Hex base#:
+16 digits: 9876543210abcedf
+17 digits: 876543210abcedfc
+18 digits: 76543210abcedfcc
+16 digits: 6789abcdef543121
+17 digits: 789abcdef5431204
+18 digits: 89abcdef54312034
diff --git a/shell/ash_test/ash-arith/arith-bignum1.tests b/shell/ash_test/ash-arith/arith-bignum1.tests
new file mode 100755
index 0000000..ef8f928
--- /dev/null
+++ b/shell/ash_test/ash-arith/arith-bignum1.tests
@@ -0,0 +1,17 @@
+exec 2>&1
+# If the number does not fit in 64 bits, bash uses truncated 64-bit value
+# (essentially, it does not check for overflow in "n = n * base + digit"
+# calculation).
+echo 18 digits: $((999999999999999999))
+echo 19 digits: $((9999999999999999999))
+echo 20 digits: $((99999999999999999999))
+echo 18 digits- $((-999999999999999999))
+echo 19 digits- $((-9999999999999999999))
+echo 20 digits- $((-99999999999999999999))
+echo "Hex base#:"
+printf '16 digits: %016x\n' $((16#9876543210abcedf))
+printf '17 digits: %016x\n' $((16#9876543210abcedfc))
+printf '18 digits: %016x\n' $((16#9876543210abcedfcc))
+printf '16 digits: %016x\n' $((-16#9876543210abcedf))
+printf '17 digits: %016x\n' $((-16#9876543210abcedfc))
+printf '18 digits: %016x\n' $((-16#9876543210abcedfcc))
diff --git a/shell/ash_test/ash-arith/arith.right b/shell/ash_test/ash-arith/arith.right
index 8bc78b8..b2c3f56 100644
--- a/shell/ash_test/ash-arith/arith.right
+++ b/shell/ash_test/ash-arith/arith.right
@@ -80,8 +80,9 @@ other bases
62 62
63 63
missing number after base
-0 0
+./arith.tests: line 161: arithmetic syntax error
./arith.tests: line 162: arithmetic syntax error
+./arith.tests: line 163: arithmetic syntax error
./arith.tests: line 164: divide by zero
./arith.tests: let: line 165: arithmetic syntax error
./arith.tests: line 166: arithmetic syntax error
diff --git a/shell/ash_test/ash-arith/arith.tests b/shell/ash_test/ash-arith/arith.tests
index b9cb8ba..42cd7fd 100755
--- a/shell/ash_test/ash-arith/arith.tests
+++ b/shell/ash_test/ash-arith/arith.tests
@@ -155,12 +155,12 @@ echo 63 $(( 64#_ ))
#ash# # weird bases (error)
#ash# echo $(( 3425#56 ))
-echo missing number after base
-echo 0 $(( 2# ))
# these should generate errors
+echo missing number after base
+( echo $(( 2# )) )
( echo $(( 7 = 43 )) )
-#ash# echo $(( 2#44 ))
+( echo $(( 2#44 )) )
( echo $(( 44 / 0 )) )
( let 'jv += $iv' )
( echo $(( jv += \$iv )) )