aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/src/eval_bits.erl
diff options
context:
space:
mode:
authorAnthony Ramine <[email protected]>2013-03-28 08:52:43 +0100
committerFredrik Gustafsson <[email protected]>2013-06-05 12:08:39 +0200
commit90efeaf21147505b1e8207822e606027f94183cc (patch)
treea8f4709a1625aa7ac96e67b08a43119943aae34a /lib/stdlib/src/eval_bits.erl
parent872987787b0d95b89c45920c8b5453a86580d201 (diff)
downloadotp-90efeaf21147505b1e8207822e606027f94183cc.tar.gz
otp-90efeaf21147505b1e8207822e606027f94183cc.tar.bz2
otp-90efeaf21147505b1e8207822e606027f94183cc.zip
Forbid unsized fields in patterns of binary generators
It makes no sense to be able to do `<<...,Rest/binary>> <= ...` in a comprehension. The related Dialyzer test is removed.
Diffstat (limited to 'lib/stdlib/src/eval_bits.erl')
-rw-r--r--lib/stdlib/src/eval_bits.erl19
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/stdlib/src/eval_bits.erl b/lib/stdlib/src/eval_bits.erl
index e49cbc1fd1..75fe2c00c7 100644
--- a/lib/stdlib/src/eval_bits.erl
+++ b/lib/stdlib/src/eval_bits.erl
@@ -192,7 +192,7 @@ bin_gen_field({bin_element,Line,VE,Size0,Options0},
make_bit_type(Line, Size0, Options0),
V = erl_eval:partial_eval(VE),
NewV = coerce_to_float(V, Type),
- match_check_size(Mfun, Size1, BBs0),
+ match_check_size(Mfun, Size1, BBs0, false),
{value, Size, _BBs} = Efun(Size1, BBs0),
bin_gen_field1(Bin, Type, Size, Unit, Sign, Endian, NewV, Bs0, BBs0, Mfun).
@@ -380,20 +380,25 @@ make_bit_type(_Line, Size, Type0) -> %Size evaluates to an integer or 'all'
{error,Reason} -> error(Reason)
end.
-match_check_size(Mfun, {var,_,V}, Bs) ->
+match_check_size(Mfun, Size, Bs) ->
+ match_check_size(Mfun, Size, Bs, true).
+
+match_check_size(Mfun, {var,_,V}, Bs, _AllowAll) ->
case Mfun(binding, {V,Bs}) of
{value,_} -> ok;
unbound -> throw(invalid) % or, rather, error({unbound,V})
end;
-match_check_size(_, {atom,_,all}, _Bs) ->
+match_check_size(_, {atom,_,all}, _Bs, true) ->
ok;
-match_check_size(_, {atom,_,undefined}, _Bs) ->
+match_check_size(_, {atom,_,all}, _Bs, false) ->
+ throw(invalid);
+match_check_size(_, {atom,_,undefined}, _Bs, _AllowAll) ->
ok;
-match_check_size(_, {integer,_,_}, _Bs) ->
+match_check_size(_, {integer,_,_}, _Bs, _AllowAll) ->
ok;
-match_check_size(_, {value,_,_}, _Bs) ->
+match_check_size(_, {value,_,_}, _Bs, _AllowAll) ->
ok; %From the debugger.
-match_check_size(_, _, _Bs) ->
+match_check_size(_, _, _Bs, _AllowAll) ->
throw(invalid).
%% error(Reason) -> exception thrown