diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2023-06-25 17:42:05 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2023-06-25 17:42:05 +0200 |
commit | c1c267fd36b0fcac8c8871232eecc1e360173990 (patch) | |
tree | 83a490c0098926b5e5ef66f474c2b8a6dcfd6620 /shell/ash_test | |
parent | 019dd31150526b7dd9dd0addfc38f08bcf7ec551 (diff) | |
download | busybox-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.right | 13 | ||||
-rwxr-xr-x | shell/ash_test/ash-arith/arith-bignum1.tests | 17 | ||||
-rw-r--r-- | shell/ash_test/ash-arith/arith.right | 3 | ||||
-rwxr-xr-x | shell/ash_test/ash-arith/arith.tests | 6 |
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 @@ | |||
1 | 18 digits: 999999999999999999 | ||
2 | 19 digits: -8446744073709551617 | ||
3 | 20 digits: 7766279631452241919 | ||
4 | 18 digits- -999999999999999999 | ||
5 | 19 digits- 8446744073709551617 | ||
6 | 20 digits- -7766279631452241919 | ||
7 | Hex base#: | ||
8 | 16 digits: 9876543210abcedf | ||
9 | 17 digits: 876543210abcedfc | ||
10 | 18 digits: 76543210abcedfcc | ||
11 | 16 digits: 6789abcdef543121 | ||
12 | 17 digits: 789abcdef5431204 | ||
13 | 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 000000000..ef8f928bc --- /dev/null +++ b/shell/ash_test/ash-arith/arith-bignum1.tests | |||
@@ -0,0 +1,17 @@ | |||
1 | exec 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). | ||
5 | echo 18 digits: $((999999999999999999)) | ||
6 | echo 19 digits: $((9999999999999999999)) | ||
7 | echo 20 digits: $((99999999999999999999)) | ||
8 | echo 18 digits- $((-999999999999999999)) | ||
9 | echo 19 digits- $((-9999999999999999999)) | ||
10 | echo 20 digits- $((-99999999999999999999)) | ||
11 | echo "Hex base#:" | ||
12 | printf '16 digits: %016x\n' $((16#9876543210abcedf)) | ||
13 | printf '17 digits: %016x\n' $((16#9876543210abcedfc)) | ||
14 | printf '18 digits: %016x\n' $((16#9876543210abcedfcc)) | ||
15 | printf '16 digits: %016x\n' $((-16#9876543210abcedf)) | ||
16 | printf '17 digits: %016x\n' $((-16#9876543210abcedfc)) | ||
17 | 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 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 | |||
80 | 62 62 | 80 | 62 62 |
81 | 63 63 | 81 | 63 63 |
82 | missing number after base | 82 | missing number after base |
83 | 0 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 | ||
158 | echo missing number after base | ||
159 | echo 0 $(( 2# )) | ||
160 | 158 | ||
161 | # these should generate errors | 159 | # these should generate errors |
160 | echo 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 )) ) |