aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/test/bs_construct_SUITE.erl
diff options
context:
space:
mode:
authorErlang/OTP <[email protected]>2017-08-23 10:39:24 +0200
committerErlang/OTP <[email protected]>2017-08-23 10:39:24 +0200
commit73ecd4cde263c4179e774958ce9c45cb5bfc3fad (patch)
treefbe2377d20b7e8975814efb5c8033171f53c575d /erts/emulator/test/bs_construct_SUITE.erl
parent345a79ac188caa24229195991ed134e1e4df8179 (diff)
parent0322232e3603ae098177e7fe5fcf81f2ed58ea00 (diff)
downloadotp-73ecd4cde263c4179e774958ce9c45cb5bfc3fad.tar.gz
otp-73ecd4cde263c4179e774958ce9c45cb5bfc3fad.tar.bz2
otp-73ecd4cde263c4179e774958ce9c45cb5bfc3fad.zip
Merge branch 'john/erts/fix-binary-append-syslimit/OTP-14524' into maint-20
* john/erts/fix-binary-append-syslimit/OTP-14524: Check for overflow when appending binaries, and error out with system_limit # Conflicts: # erts/emulator/test/bs_construct_SUITE.erl
Diffstat (limited to 'erts/emulator/test/bs_construct_SUITE.erl')
-rw-r--r--erts/emulator/test/bs_construct_SUITE.erl24
1 files changed, 19 insertions, 5 deletions
diff --git a/erts/emulator/test/bs_construct_SUITE.erl b/erts/emulator/test/bs_construct_SUITE.erl
index b79f4b995d..ce50bcdd86 100644
--- a/erts/emulator/test/bs_construct_SUITE.erl
+++ b/erts/emulator/test/bs_construct_SUITE.erl
@@ -905,14 +905,28 @@ bs_add_overflow(_Config) ->
_ when Memsize < (2 bsl 30) ->
{skip, "Less then 2 GB of memory"};
4 ->
- Large = <<0:((1 bsl 30)-1)>>,
- {'EXIT',{system_limit,_}} =
- (catch <<Large/bits, Large/bits, Large/bits, Large/bits,
- Large/bits, Large/bits, Large/bits, Large/bits,
- Large/bits>>),
+ {'EXIT', {system_limit, _}} = (catch bs_add_overflow_signed()),
+ {'EXIT', {system_limit, _}} = (catch bs_add_overflow_unsigned()),
ok
end.
+bs_add_overflow_signed() ->
+ %% Produce a large result of bs_add that, if cast to signed int, would
+ %% overflow into a negative number that fits a smallnum.
+ Large = <<0:((1 bsl 30)-1)>>,
+ <<Large/bits, Large/bits, Large/bits, Large/bits,
+ Large/bits, Large/bits, Large/bits, Large/bits,
+ Large/bits>>.
+
+bs_add_overflow_unsigned() ->
+ %% Produce a large result of bs_add that goes beyond the limit of an
+ %% unsigned word. This used to succeed but produced an incorrect result
+ %% where B =:= C!
+ A = <<0:((1 bsl 32)-8)>>,
+ B = <<2, 3>>,
+ C = <<A/binary,1,B/binary>>,
+ true = byte_size(B) < byte_size(C).
+
id(I) -> I.
memsize() ->