aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1/src
diff options
context:
space:
mode:
authorGustav Simonsson <[email protected]>2012-08-15 17:29:19 +0200
committerGustav Simonsson <[email protected]>2012-08-15 17:29:19 +0200
commitd7b165788d2aec28a652281a4c4310bda95c4fbf (patch)
tree7113793add62e8d7be730a3ca45ad0aaf2163fcc /lib/asn1/src
parent80cada1182d0a1a8afc84e3c3fa316bcf5649736 (diff)
parentcc665e1ccb2cfc14a1ac8afefdc7af715ef5dee4 (diff)
downloadotp-d7b165788d2aec28a652281a4c4310bda95c4fbf.tar.gz
otp-d7b165788d2aec28a652281a4c4310bda95c4fbf.tar.bz2
otp-d7b165788d2aec28a652281a4c4310bda95c4fbf.zip
Merge branch 'gustav/asn1/integer_single_value_predefined/OTP-10139' into maint
* gustav/asn1/integer_single_value_predefined/OTP-10139: In generation of encoding functions for enumeration types, the values used for generating the range check in case of a value range should be sorted and have duplicates removed. Add sorting in constraint checking on single values. Conflicts: lib/asn1/test/testConstraints.erl
Diffstat (limited to 'lib/asn1/src')
-rw-r--r--lib/asn1/src/asn1ct_check.erl2
-rw-r--r--lib/asn1/src/asn1ct_gen_per.erl16
-rw-r--r--lib/asn1/src/asn1ct_gen_per_rt2ct.erl15
3 files changed, 11 insertions, 22 deletions
diff --git a/lib/asn1/src/asn1ct_check.erl b/lib/asn1/src/asn1ct_check.erl
index 494a2eddd9..59e82b7a57 100644
--- a/lib/asn1/src/asn1ct_check.erl
+++ b/lib/asn1/src/asn1ct_check.erl
@@ -4177,7 +4177,7 @@ check_constraint(S,{'SizeConstraint',Lb}) ->
check_constraint(S,{'SingleValue', L}) when is_list(L) ->
F = fun(A) -> resolv_value(S,A) end,
- {'SingleValue',lists:map(F,L)};
+ {'SingleValue',lists:sort(lists:map(F,L))};
check_constraint(S,{'SingleValue', V}) when is_integer(V) ->
Val = resolv_value(S,V),
diff --git a/lib/asn1/src/asn1ct_gen_per.erl b/lib/asn1/src/asn1ct_gen_per.erl
index 5f42eacbdc..bd5b81991d 100644
--- a/lib/asn1/src/asn1ct_gen_per.erl
+++ b/lib/asn1/src/asn1ct_gen_per.erl
@@ -321,19 +321,13 @@ effective_constr(_,[]) ->
[];
effective_constr('SingleValue',List) ->
SVList = lists:flatten(lists:map(fun(X)->element(2,X)end,List)),
- % sort and remove duplicates
- SortedSVList = lists:sort(SVList),
- RemoveDup = fun([],_) ->[];
- ([H],_) -> [H];
- ([H,H|T],F) -> F([H|T],F);
- ([H|T],F) -> [H|F(T,F)]
- end,
-
- case RemoveDup(SortedSVList,RemoveDup) of
+ %% Sort and remove duplicates before generating SingleValue or ValueRange
+ %% In case of ValueRange, also check for 'MIN and 'MAX'
+ case lists:usort(SVList) of
[N] ->
[{'SingleValue',N}];
- L when is_list(L) ->
- [{'ValueRange',{hd(L),lists:last(L)}}]
+ L when is_list(L) ->
+ [{'ValueRange',{least_Lb(L),greatest_Ub(L)}}]
end;
effective_constr('ValueRange',List) ->
LBs = lists:map(fun({_,{Lb,_}})-> Lb end,List),
diff --git a/lib/asn1/src/asn1ct_gen_per_rt2ct.erl b/lib/asn1/src/asn1ct_gen_per_rt2ct.erl
index eda0faad3c..16eec92847 100644
--- a/lib/asn1/src/asn1ct_gen_per_rt2ct.erl
+++ b/lib/asn1/src/asn1ct_gen_per_rt2ct.erl
@@ -670,18 +670,13 @@ effective_constr(_,[]) ->
[];
effective_constr('SingleValue',List) ->
SVList = lists:flatten(lists:map(fun(X)->element(2,X)end,List)),
- % sort and remove duplicates
- RemoveDup = fun([],_) ->[];
- ([H],_) -> [H];
- ([H,H|T],F) -> F([H|T],F);
- ([H|T],F) -> [H|F(T,F)]
- end,
-
- case RemoveDup(SVList,RemoveDup) of
+ %% Sort and remove duplicates before generating SingleValue or ValueRange
+ %% In case of ValueRange, also check for 'MIN and 'MAX'
+ case lists:usort(SVList) of
[N] ->
[{'SingleValue',N}];
- L when is_list(L) ->
- [{'ValueRange',{hd(L),lists:last(L)}}]
+ L when is_list(L) ->
+ [{'ValueRange',{least_Lb(L),greatest_Ub(L)}}]
end;
effective_constr('ValueRange',List) ->
LBs = lists:map(fun({_,{Lb,_}})-> Lb end,List),