From 727ea85b458865daf39fef07a8cd8308420e2a1a Mon Sep 17 00:00:00 2001
From: Kenneth Lundin <kenneth@erlang.org>
Date: Mon, 23 Aug 2010 15:50:13 +0200
Subject: Fix bug in UNALIGNED PER regarding encode/decode of constrained
 number with valuerange > 1024

OTP-8779
Thanks to Vincent de Phily
---
 lib/asn1/src/asn1rt_uper_bin.erl | 29 ++++++-----------------------
 1 file changed, 6 insertions(+), 23 deletions(-)

(limited to 'lib')

diff --git a/lib/asn1/src/asn1rt_uper_bin.erl b/lib/asn1/src/asn1rt_uper_bin.erl
index a964b835ae..abe178a69e 100644
--- a/lib/asn1/src/asn1rt_uper_bin.erl
+++ b/lib/asn1/src/asn1rt_uper_bin.erl
@@ -1,7 +1,7 @@
 %%
 %% %CopyrightBegin%
 %% 
-%% Copyright Ericsson AB 2008-2009. All Rights Reserved.
+%% Copyright Ericsson AB 2008-2010. All Rights Reserved.
 %% 
 %% The contents of this file are subject to the Erlang Public License,
 %% Version 1.1, (the "License"); you may not use this file except in
@@ -1611,25 +1611,8 @@ complete_NFP(InList) when is_bitstring(InList) ->
 
 %% 10.5.6 NOTE: If "range" satisfies the inequality 2^m < "range" =<
 %% 2^(m+1) then the number of bits = m + 1
-num_bits(1) -> 0;
-num_bits(2) -> 1;
-num_bits(R) when R =< 4 -> 
-    2;
-num_bits(R) when R =< 8 ->
-    3;
-num_bits(R) when R =< 16 ->
-    4;
-num_bits(R) when R =< 32 ->
-    5;	
-num_bits(R) when R =< 64 ->
-    6;
-num_bits(R) when R =< 128 ->
-    7;
-num_bits(R) when R =< 256 ->
-    8;
-num_bits(R) when R =< 512 ->
-    9;
-num_bits(R) when R =< 1024 ->
-    10;
-num_bits(R) ->
-    1+num_bits(R bsr 1).
+
+num_bits(N) ->
+    num_bits(N,1,0).
+num_bits(N,T,B) when N=<T->B;
+num_bits(N,T,B) ->num_bits(N,T bsl 1, B+1).
-- 
cgit v1.2.3