diff options
author | Björn Gustavsson <[email protected]> | 2012-12-21 11:09:31 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2013-01-22 19:20:13 +0100 |
commit | 3f8be66021a5b3ce764181a2f9685ed7bfc81607 (patch) | |
tree | b92b417fa632fc87dace0a572b38de9c3f42fd12 /lib/asn1 | |
parent | 53210f62a94126b643666886dfbefb8bae9e86a2 (diff) | |
download | otp-3f8be66021a5b3ce764181a2f9685ed7bfc81607.tar.gz otp-3f8be66021a5b3ce764181a2f9685ed7bfc81607.tar.bz2 otp-3f8be66021a5b3ce764181a2f9685ed7bfc81607.zip |
Enumeration decoding: Don't emit a default clause if it cannot match
Dialyzer will warn for default clauses that cannot possible match.
Diffstat (limited to 'lib/asn1')
-rw-r--r-- | lib/asn1/src/asn1ct_imm.erl | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/asn1/src/asn1ct_imm.erl b/lib/asn1/src/asn1ct_imm.erl index 7eb807aa5e..d0459ae60b 100644 --- a/lib/asn1/src/asn1ct_imm.erl +++ b/lib/asn1/src/asn1ct_imm.erl @@ -60,9 +60,17 @@ per_dec_boolean() -> {map,{get_bits,1,[1]},[{0,false},{1,true}]}. per_dec_enumerated(NamedList0, Aligned) -> - Constraint = [{'ValueRange',{0,length(NamedList0)-1}}], - NamedList = per_dec_enumerated_fix_list(NamedList0, [enum_error], 0), + Ub = length(NamedList0) - 1, + Constraint = [{'ValueRange',{0,Ub}}], Int = per_dec_integer(Constraint, Aligned), + EnumTail = case matched_range(Int) of + {0,Ub} -> + %% The error case can never happen. + []; + _ -> + [enum_error] + end, + NamedList = per_dec_enumerated_fix_list(NamedList0, EnumTail, 0), {map,Int,NamedList}. per_dec_enumerated(BaseNamedList, NamedListExt0, Aligned) -> @@ -241,6 +249,16 @@ per_num_bits(N) when N =< 64 -> 6; per_num_bits(N) when N =< 128 -> 7; per_num_bits(N) when N =< 255 -> 8. +matched_range({get_bits,Bits0,[U|Flags]}) when is_integer(U) -> + case lists:member(signed, Flags) of + false -> + Bits = U*Bits0, + {0,(1 bsl Bits) - 1}; + true -> + unknown + end; +matched_range(_Op) -> unknown. + %%% %%% Remove unnecessary aligning to octet boundaries. %%% |