From 793dd44c6cdb892de9d1b44694fd4069726030cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Tue, 30 Oct 2012 08:28:11 +0100 Subject: Fix binary append exceptions Code such as the following should cause an exception: Bin = <<0:1>>, <> (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 --- erts/emulator/test/bs_bit_binaries_SUITE.erl | 43 +++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'erts/emulator/test/bs_bit_binaries_SUITE.erl') diff --git a/erts/emulator/test/bs_bit_binaries_SUITE.erl b/erts/emulator/test/bs_bit_binaries_SUITE.erl index ff1088118d..1428387a65 100644 --- a/erts/emulator/test/bs_bit_binaries_SUITE.erl +++ b/erts/emulator/test/bs_bit_binaries_SUITE.erl @@ -177,14 +177,55 @@ append(Config) when is_list(Config) -> cs_init(), ?line <<(-1):256/signed-unit:8>> = cs(do_append(id(<<>>), 256*8)), ?line <<(-1):256/signed-unit:8>> = cs(do_append2(id(<<>>), 256*4)), + <<(-1):256/signed-unit:8>> = cs(do_append3(id(<<>>), 256*8)), cs_end(). do_append(Bin, N) when N > 0 -> do_append(<>, N-1); do_append(Bin, 0) -> Bin. -do_append2(Bin, N) when N > 0 -> do_append2(<>, N-1); +do_append2(Bin, N) when N > 0 -> do_append2(<>, N-1); do_append2(Bin, 0) -> Bin. +do_append3(Bin, N) when N > 0 -> + Bits = bit_size(Bin), + if + Bits rem 2 =:= 0 -> + do_append3(<>, N-1); + Bits rem 3 =:= 0 -> + do_append3(<>, N-1); + Bits rem 4 =:= 0 -> + do_append3(<>, N-1); + Bits rem 5 =:= 0 -> + do_append3(<>, N-1); + Bits rem 6 =:= 0 -> + do_append3(<>, N-1); + Bits rem 7 =:= 0 -> + do_append3(<>, N-1); + Bits rem 8 =:= 0 -> + do_append3(<>, N-1); + Bits rem 9 =:= 0 -> + do_append3(<>, N-1); + Bits rem 10 =:= 0 -> + do_append3(<>, N-1); + Bits rem 11 =:= 0 -> + do_append3(<>, N-1); + Bits rem 12 =:= 0 -> + do_append3(<>, N-1); + Bits rem 13 =:= 0 -> + do_append3(<>, N-1); + Bits rem 14 =:= 0 -> + do_append3(<>, N-1); + Bits rem 15 =:= 0 -> + do_append3(<>, N-1); + Bits rem 16 =:= 0 -> + do_append3(<>, N-1); + Bits rem 17 =:= 0 -> + do_append3(<>, N-1); + true -> + do_append3(<>, N-1) + end; +do_append3(Bin, 0) -> Bin. + cs_init() -> erts_debug:set_internal_state(available_internal_state, true), ok. -- cgit v1.2.3