aboutsummaryrefslogtreecommitdiff
path: root/shell/hush_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/hush_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/hush_test')
-rw-r--r--shell/hush_test/hush-arith/arith-bignum1.right13
-rwxr-xr-xshell/hush_test/hush-arith/arith-bignum1.tests17
-rw-r--r--shell/hush_test/hush-arith/arith.right3
-rwxr-xr-xshell/hush_test/hush-arith/arith.tests6
4 files changed, 35 insertions, 4 deletions
diff --git a/shell/hush_test/hush-arith/arith-bignum1.right b/shell/hush_test/hush-arith/arith-bignum1.right
new file mode 100644
index 000000000..42a8016ec
--- /dev/null
+++ b/shell/hush_test/hush-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/hush_test/hush-arith/arith-bignum1.tests b/shell/hush_test/hush-arith/arith-bignum1.tests
new file mode 100755
index 000000000..ef8f928bc
--- /dev/null
+++ b/shell/hush_test/hush-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/hush_test/hush-arith/arith.right b/shell/hush_test/hush-arith/arith.right
index df8154f97..d3a978611 100644
--- a/shell/hush_test/hush-arith/arith.right
+++ b/shell/hush_test/hush-arith/arith.right
@@ -82,7 +82,8 @@ other bases
8262 62 8262 62
8363 63 8363 63
84missing number after base 84missing number after base
850 0 85hush: arithmetic syntax error
86hush: arithmetic syntax error
86hush: arithmetic syntax error 87hush: arithmetic syntax error
87hush: divide by zero 88hush: divide by zero
88hush: can't execute 'let': No such file or directory 89hush: can't execute 'let': No such file or directory
diff --git a/shell/hush_test/hush-arith/arith.tests b/shell/hush_test/hush-arith/arith.tests
index 6b707486c..9f0399816 100755
--- a/shell/hush_test/hush-arith/arith.tests
+++ b/shell/hush_test/hush-arith/arith.tests
@@ -159,12 +159,12 @@ echo 63 $(( 64#_ ))
159#ash# # weird bases (error) 159#ash# # weird bases (error)
160#ash# echo $(( 3425#56 )) 160#ash# echo $(( 3425#56 ))
161 161
162echo missing number after base
163echo 0 $(( 2# ))
164 162
165# these should generate errors 163# these should generate errors
164echo missing number after base
165( echo $(( 2# )) )
166( echo $(( 7 = 43 )) ) 166( echo $(( 7 = 43 )) )
167#ash# echo $(( 2#44 )) 167( echo $(( 2#44 )) )
168( echo $(( 44 / 0 )) ) 168( echo $(( 44 / 0 )) )
169( let 'jv += $iv' ) 169( let 'jv += $iv' )
170( echo $(( jv += \$iv )) ) 170( echo $(( jv += \$iv )) )