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/hush_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/hush_test')
-rw-r--r-- | shell/hush_test/hush-arith/arith-bignum1.right | 13 | ||||
-rwxr-xr-x | shell/hush_test/hush-arith/arith-bignum1.tests | 17 | ||||
-rw-r--r-- | shell/hush_test/hush-arith/arith.right | 3 | ||||
-rwxr-xr-x | shell/hush_test/hush-arith/arith.tests | 6 |
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 @@ | |||
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/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 @@ | |||
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/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 | |||
82 | 62 62 | 82 | 62 62 |
83 | 63 63 | 83 | 63 63 |
84 | missing number after base | 84 | missing number after base |
85 | 0 0 | 85 | hush: arithmetic syntax error |
86 | hush: arithmetic syntax error | ||
86 | hush: arithmetic syntax error | 87 | hush: arithmetic syntax error |
87 | hush: divide by zero | 88 | hush: divide by zero |
88 | hush: can't execute 'let': No such file or directory | 89 | hush: 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 | ||
162 | echo missing number after base | ||
163 | echo 0 $(( 2# )) | ||
164 | 162 | ||
165 | # these should generate errors | 163 | # these should generate errors |
164 | echo 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 )) ) |