diff options
author | Björn Gustavsson <[email protected]> | 2012-10-30 08:28:11 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2012-11-05 12:19:29 +0100 |
commit | 793dd44c6cdb892de9d1b44694fd4069726030cc (patch) | |
tree | bdb14c473ab065fccd2928254e8bc8aed5ea81bd /erts/emulator/test/bs_construct_SUITE.erl | |
parent | e85c4dda93e416e8e97c0dcfadc5eeaf5bd8b4e1 (diff) | |
download | otp-793dd44c6cdb892de9d1b44694fd4069726030cc.tar.gz otp-793dd44c6cdb892de9d1b44694fd4069726030cc.tar.bz2 otp-793dd44c6cdb892de9d1b44694fd4069726030cc.zip |
Fix binary append exceptions
Code such as the following should cause an exception:
Bin = <<0:1>>,
<<Bin/binary,...>>
(Because the "binary" type implies that the binary must have a
size in bits that is a multiple of 8.)
Depending on the binary, either no exception was thrown or the
wrong exception was thrown (because c_p->freason was not set).
Noticed-by: Adam Rutkowski
Diffstat (limited to 'erts/emulator/test/bs_construct_SUITE.erl')
-rw-r--r-- | erts/emulator/test/bs_construct_SUITE.erl | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/erts/emulator/test/bs_construct_SUITE.erl b/erts/emulator/test/bs_construct_SUITE.erl index 8b5c82d968..9c88803fea 100644 --- a/erts/emulator/test/bs_construct_SUITE.erl +++ b/erts/emulator/test/bs_construct_SUITE.erl @@ -28,7 +28,7 @@ mem_leak/1, coerce_to_float/1, bjorn/1, huge_float_field/1, huge_binary/1, system_limit/1, badarg/1, copy_writable_binary/1, kostis/1, dynamic/1, bs_add/1, - otp_7422/1, zero_width/1]). + otp_7422/1, zero_width/1, bad_append/1]). -include_lib("test_server/include/test_server.hrl"). @@ -38,7 +38,8 @@ all() -> [test1, test2, test3, test4, test5, testf, not_used, in_guard, mem_leak, coerce_to_float, bjorn, huge_float_field, huge_binary, system_limit, badarg, - copy_writable_binary, kostis, dynamic, bs_add, otp_7422, zero_width]. + copy_writable_binary, kostis, dynamic, bs_add, otp_7422, zero_width, + bad_append]. groups() -> []. @@ -827,5 +828,49 @@ zero_width(Config) when is_list(Config) -> ?line {'EXIT',{badarg,_}} = (catch <<(id(not_a_number)):0>>), ok. + +bad_append(_) -> + do_bad_append(<<127:1>>, fun append_unit_3/1), + do_bad_append(<<127:2>>, fun append_unit_3/1), + do_bad_append(<<127:17>>, fun append_unit_3/1), + + do_bad_append(<<127:3>>, fun append_unit_4/1), + do_bad_append(<<127:5>>, fun append_unit_4/1), + do_bad_append(<<127:7>>, fun append_unit_4/1), + do_bad_append(<<127:199>>, fun append_unit_4/1), + + do_bad_append(<<127:7>>, fun append_unit_8/1), + do_bad_append(<<127:9>>, fun append_unit_8/1), + + do_bad_append(<<0:8>>, fun append_unit_16/1), + do_bad_append(<<0:15>>, fun append_unit_16/1), + do_bad_append(<<0:17>>, fun append_unit_16/1), + ok. + +do_bad_append(Bin0, Appender) -> + {'EXIT',{badarg,_}} = (catch Appender(Bin0)), + + Bin1 = id(<<0:3,Bin0/bitstring>>), + <<_:3,Bin2/bitstring>> = Bin1, + {'EXIT',{badarg,_}} = (catch Appender(Bin2)), + + %% Create a writable binary. + Empty = id(<<>>), + Bin3 = <<Empty/bitstring,Bin0/bitstring>>, + {'EXIT',{badarg,_}} = (catch Appender(Bin3)), + ok. + +append_unit_3(Bin) -> + <<Bin/binary-unit:3,0:1>>. + +append_unit_4(Bin) -> + <<Bin/binary-unit:4,0:1>>. + +append_unit_8(Bin) -> + <<Bin/binary,0:1>>. + +append_unit_16(Bin) -> + <<Bin/binary-unit:16,0:1>>. + id(I) -> I. |