diff options
author | Björn Gustavsson <[email protected]> | 2011-03-14 15:15:09 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2011-03-23 11:07:52 +0100 |
commit | c7188f410f5d2688783dfbb850e1e55718885f87 (patch) | |
tree | fb4eec23ff53a0ec9b1c4ff5e4d25d1718194745 /lib/compiler/test | |
parent | b412280c8591300b22386c21fb109da3a697c0c9 (diff) | |
download | otp-c7188f410f5d2688783dfbb850e1e55718885f87.tar.gz otp-c7188f410f5d2688783dfbb850e1e55718885f87.tar.bz2 otp-c7188f410f5d2688783dfbb850e1e55718885f87.zip |
v3_core: Fix variable incorrectly unbound after binary match
In the following code:
m(<<Sz:8,_:Sz/binary>>) ->
Sz = wrong.
the Sz variable is supposed to be bound in the function header and the
matching "Sz = wrong" should cause a badarg exception. But what
happens is that the Sz variables seems to be unbound and the matching
succeds and the m/1 function returns 'wrong'.
If the Sz variable is used directly (not matched), it will have
the expected value. Thus the following code:
m(<<Sz:8,_:Sz/binary>>) ->
Sz.
will correctly return the value of Sz that was matched out from
the binary.
Reported-by: Bernard Duggan
Diffstat (limited to 'lib/compiler/test')
-rw-r--r-- | lib/compiler/test/bs_match_SUITE.erl | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/compiler/test/bs_match_SUITE.erl b/lib/compiler/test/bs_match_SUITE.erl index 1e3c670fb8..9184e14cb2 100644 --- a/lib/compiler/test/bs_match_SUITE.erl +++ b/lib/compiler/test/bs_match_SUITE.erl @@ -142,7 +142,14 @@ otp_5269(Config) when is_list(Config) -> [X || <<X:X>> <- [<<1:32>>,<<2:32>>,<<3:8>>]] end, %% "binsize variable" ^ [1,2]), - + ?line check(fun() -> + (fun (<<A:1/binary, B:8/integer, _C:B/binary>>) -> + case A of + B -> wrong; + _ -> ok + end + end)(<<1,2,3,4>>) end, + ok), ok. null_fields(Config) when is_list(Config) -> |