aboutsummaryrefslogtreecommitdiff
path: root/shell/ash_test
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2023-06-25 17:42:05 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2023-06-25 17:42:05 +0200
commitc1c267fd36b0fcac8c8871232eecc1e360173990 (patch)
tree83a490c0098926b5e5ef66f474c2b8a6dcfd6620 /shell/ash_test
parent019dd31150526b7dd9dd0addfc38f08bcf7ec551 (diff)
downloadbusybox-w32-c1c267fd36b0fcac8c8871232eecc1e360173990.tar.gz
busybox-w32-c1c267fd36b0fcac8c8871232eecc1e360173990.tar.bz2
busybox-w32-c1c267fd36b0fcac8c8871232eecc1e360173990.zip
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')
-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 000000000..42a8016ec
--- /dev/null
+++ b/shell/ash_test/ash-arith/arith-bignum1.right
@@ -0,0 +1,13 @@
118 digits: 999999999999999999
219 digits: -8446744073709551617
320 digits: 7766279631452241919
418 digits- -999999999999999999
519 digits- 8446744073709551617
620 digits- -7766279631452241919
7Hex base#:
816 digits: 9876543210abcedf
917 digits: 876543210abcedfc
1018 digits: 76543210abcedfcc
1116 digits: 6789abcdef543121
1217 digits: 789abcdef5431204
1318 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 000000000..ef8f928bc
--- /dev/null
+++ b/shell/ash_test/ash-arith/arith-bignum1.tests
@@ -0,0 +1,17 @@
1exec 2>&1
2# If the number does not fit in 64 bits, bash uses truncated 64-bit value
3# (essentially, it does not check for overflow in "n = n * base + digit"
4# calculation).
5echo 18 digits: $((999999999999999999))
6echo 19 digits: $((9999999999999999999))
7echo 20 digits: $((99999999999999999999))
8echo 18 digits- $((-999999999999999999))
9echo 19 digits- $((-9999999999999999999))
10echo 20 digits- $((-99999999999999999999))
11echo "Hex base#:"
12printf '16 digits: %016x\n' $((16#9876543210abcedf))
13printf '17 digits: %016x\n' $((16#9876543210abcedfc))
14printf '18 digits: %016x\n' $((16#9876543210abcedfcc))
15printf '16 digits: %016x\n' $((-16#9876543210abcedf))
16printf '17 digits: %016x\n' $((-16#9876543210abcedfc))
17printf '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 8bc78b8d1..b2c3f56d8 100644
--- a/shell/ash_test/ash-arith/arith.right
+++ b/shell/ash_test/ash-arith/arith.right
@@ -80,8 +80,9 @@ other bases
8062 62 8062 62
8163 63 8163 63
82missing number after base 82missing number after base
830 0 83./arith.tests: line 161: arithmetic syntax error
84./arith.tests: line 162: arithmetic syntax error 84./arith.tests: line 162: arithmetic syntax error
85./arith.tests: line 163: arithmetic syntax error
85./arith.tests: line 164: divide by zero 86./arith.tests: line 164: divide by zero
86./arith.tests: let: line 165: arithmetic syntax error 87./arith.tests: let: line 165: arithmetic syntax error
87./arith.tests: line 166: arithmetic syntax error 88./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 b9cb8ba4c..42cd7fdbf 100755
--- a/shell/ash_test/ash-arith/arith.tests
+++ b/shell/ash_test/ash-arith/arith.tests
@@ -155,12 +155,12 @@ echo 63 $(( 64#_ ))
155#ash# # weird bases (error) 155#ash# # weird bases (error)
156#ash# echo $(( 3425#56 )) 156#ash# echo $(( 3425#56 ))
157 157
158echo missing number after base
159echo 0 $(( 2# ))
160 158
161# these should generate errors 159# these should generate errors
160echo missing number after base
161( echo $(( 2# )) )
162( echo $(( 7 = 43 )) ) 162( echo $(( 7 = 43 )) )
163#ash# echo $(( 2#44 )) 163( echo $(( 2#44 )) )
164( echo $(( 44 / 0 )) ) 164( echo $(( 44 / 0 )) )
165( let 'jv += $iv' ) 165( let 'jv += $iv' )
166( echo $(( jv += \$iv )) ) 166( echo $(( jv += \$iv )) )