Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
asn1c
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
asn1c
Commits
51735138
Unverified
Commit
51735138
authored
Aug 02, 2019
by
Mouse
Committed by
GitHub
Aug 02, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #54 from riebl/per_intmax
per_support: use intmax_t for integer constraints
parents
92d2802c
16207b15
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
41 deletions
+59
-41
skeletons/INTEGER.c
skeletons/INTEGER.c
+19
-19
skeletons/per_support.c
skeletons/per_support.c
+33
-17
skeletons/per_support.h
skeletons/per_support.h
+7
-5
No files found.
skeletons/INTEGER.c
View file @
51735138
...
...
@@ -636,11 +636,11 @@ INTEGER_decode_uper(const asn_codec_ctx_t *opt_codec_ctx,
/* #11.5.6 */
ASN_DEBUG
(
"Integer with range %d bits"
,
ct
->
range_bits
);
if
(
ct
->
range_bits
>=
0
)
{
if
((
size_t
)
ct
->
range_bits
>
8
*
sizeof
(
u
nsigned
long
))
if
((
size_t
)
ct
->
range_bits
>
8
*
sizeof
(
u
intmax_t
))
ASN__DECODE_FAILED
;
if
(
specs
&&
specs
->
field_unsigned
)
{
u
nsigned
long
uvalue
=
0
;
u
intmax_t
uvalue
=
0
;
if
(
uper_get_constrained_whole_number
(
pd
,
&
uvalue
,
ct
->
range_bits
))
ASN__DECODE_STARVED
;
...
...
@@ -650,16 +650,16 @@ INTEGER_decode_uper(const asn_codec_ctx_t *opt_codec_ctx,
if
(
asn_ulong2INTEGER
(
st
,
uvalue
))
ASN__DECODE_FAILED
;
}
else
{
u
nsigned
long
uvalue
=
0
;
long
svalue
;
u
intmax_t
uvalue
=
0
;
intmax_t
svalue
;
if
(
uper_get_constrained_whole_number
(
pd
,
&
uvalue
,
ct
->
range_bits
))
ASN__DECODE_STARVED
;
ASN_DEBUG
(
"Got value %lu + low %ld"
,
uvalue
,
ct
->
lower_bound
);
if
(
per_
long
_range_unrebase
(
uvalue
,
ct
->
lower_bound
,
if
(
per_
imax
_range_unrebase
(
uvalue
,
ct
->
lower_bound
,
ct
->
upper_bound
,
&
svalue
)
||
asn_
long
2INTEGER
(
st
,
svalue
))
{
||
asn_
imax
2INTEGER
(
st
,
svalue
))
{
ASN__DECODE_FAILED
;
}
}
...
...
@@ -715,7 +715,7 @@ INTEGER_encode_uper(const asn_TYPE_descriptor_t *td,
const
uint8_t
*
buf
;
const
uint8_t
*
end
;
const
asn_per_constraint_t
*
ct
;
long
value
=
0
;
intmax_t
value
=
0
;
if
(
!
st
||
st
->
size
==
0
)
ASN__ENCODE_FAILED
;
...
...
@@ -727,16 +727,16 @@ INTEGER_encode_uper(const asn_TYPE_descriptor_t *td,
if
(
ct
)
{
int
inext
=
0
;
if
(
specs
&&
specs
->
field_unsigned
)
{
u
nsigned
long
uval
;
if
(
asn_INTEGER2u
long
(
st
,
&
uval
))
u
intmax_t
uval
;
if
(
asn_INTEGER2u
max
(
st
,
&
uval
))
ASN__ENCODE_FAILED
;
/* Check proper range */
if
(
ct
->
flags
&
APC_SEMI_CONSTRAINED
)
{
if
(
uval
<
(
u
nsigned
long
)
ct
->
lower_bound
)
if
(
uval
<
(
u
intmax_t
)
ct
->
lower_bound
)
inext
=
1
;
}
else
if
(
ct
->
range_bits
>=
0
)
{
if
(
uval
<
(
u
nsigned
long
)
ct
->
lower_bound
||
uval
>
(
u
nsigned
long
)
ct
->
upper_bound
)
if
(
uval
<
(
u
intmax_t
)
ct
->
lower_bound
||
uval
>
(
u
intmax_t
)
ct
->
upper_bound
)
inext
=
1
;
}
ASN_DEBUG
(
"Value %lu (%02x/%"
ASN_PRI_SIZE
") lb %lu ub %lu %s"
,
...
...
@@ -745,7 +745,7 @@ INTEGER_encode_uper(const asn_TYPE_descriptor_t *td,
inext
?
"ext"
:
"fix"
);
value
=
uval
;
}
else
{
if
(
asn_INTEGER2
long
(
st
,
&
value
))
if
(
asn_INTEGER2
imax
(
st
,
&
value
))
ASN__ENCODE_FAILED
;
/* Check proper range */
if
(
ct
->
flags
&
APC_SEMI_CONSTRAINED
)
{
...
...
@@ -773,22 +773,22 @@ INTEGER_encode_uper(const asn_TYPE_descriptor_t *td,
/* X.691-11/2008, #13.2.2, test if constrained whole number */
if
(
ct
&&
ct
->
range_bits
>=
0
)
{
unsigned
long
v
;
uintmax_t
v
;
/* #11.5.6 -> #11.3 */
ASN_DEBUG
(
"Encoding integer %ld (%lu) with range %d bits"
,
value
,
value
-
ct
->
lower_bound
,
ct
->
range_bits
);
if
(
specs
&&
specs
->
field_unsigned
)
{
if
(
((
u
nsigned
long
)
ct
->
lower_bound
>
(
unsigned
long
)(
ct
->
upper_bound
)
||
((
u
nsigned
long
)
value
<
(
unsigned
long
)
ct
->
lower_bound
))
||
((
u
nsigned
long
)
value
>
(
unsigned
long
)
ct
->
upper_bound
)
if
(
((
u
intmax_t
)
ct
->
lower_bound
>
(
uintmax_t
)(
ct
->
upper_bound
)
||
((
u
intmax_t
)
value
<
(
uintmax_t
)
ct
->
lower_bound
))
||
((
u
intmax_t
)
value
>
(
uintmax_t
)
ct
->
upper_bound
)
)
{
ASN_DEBUG
(
"Value %lu to-be-encoded is outside the bounds [%lu, %lu]!"
,
value
,
ct
->
lower_bound
,
ct
->
upper_bound
);
ASN__ENCODE_FAILED
;
}
v
=
(
u
nsigned
long
)
value
-
(
unsigned
long
)
ct
->
lower_bound
;
v
=
(
u
intmax_t
)
value
-
(
uintmax_t
)
ct
->
lower_bound
;
}
else
{
if
(
per_
long
_range_rebase
(
value
,
ct
->
lower_bound
,
ct
->
upper_bound
,
&
v
))
{
if
(
per_
imax
_range_rebase
(
value
,
ct
->
lower_bound
,
ct
->
upper_bound
,
&
v
))
{
ASN__ENCODE_FAILED
;
}
}
...
...
skeletons/per_support.c
View file @
51735138
...
...
@@ -121,9 +121,9 @@ uper_put_nsnnwn(asn_per_outp_t *po, int n) {
/* X.691-2008/11, #11.5.6 -> #11.3 */
int
uper_get_constrained_whole_number
(
asn_per_data_t
*
pd
,
u
nsigned
long
*
out_value
,
int
nbits
)
{
u
nsigned
long
lhalf
;
/* Lower half of the number*/
long
half
;
int
uper_get_constrained_whole_number
(
asn_per_data_t
*
pd
,
u
intmax_t
*
out_value
,
int
nbits
)
{
u
intmax_t
lhalf
;
/* Lower half of the number*/
intmax_t
half
;
if
(
nbits
<=
31
)
{
half
=
per_get_few_bits
(
pd
,
nbits
);
...
...
@@ -141,7 +141,7 @@ int uper_get_constrained_whole_number(asn_per_data_t *pd, unsigned long *out_val
if
(
uper_get_constrained_whole_number
(
pd
,
&
lhalf
,
nbits
-
31
))
return
-
1
;
*
out_value
=
((
u
nsigned
long
)
half
<<
(
nbits
-
31
))
|
lhalf
;
*
out_value
=
((
u
intmax_t
)
half
<<
(
nbits
-
31
))
|
lhalf
;
return
0
;
}
...
...
@@ -216,13 +216,13 @@ uper_put_nslength(asn_per_outp_t *po, size_t length) {
}
static
int
per__
long_range
(
long
lb
,
long
ub
,
unsigned
long
*
range_r
)
{
u
nsigned
long
bounds_range
;
per__
imax_range
(
intmax_t
lb
,
intmax_t
ub
,
uintmax_t
*
range_r
)
{
u
intmax_t
bounds_range
;
if
((
ub
<
0
)
==
(
lb
<
0
))
{
bounds_range
=
ub
-
lb
;
}
else
if
(
lb
<
0
)
{
assert
(
ub
>=
0
);
bounds_range
=
1
+
((
u
nsigned
long
)
ub
+
(
unsigned
long
)
-
(
lb
+
1
));
bounds_range
=
1
+
((
u
intmax_t
)
ub
+
(
uintmax_t
)
-
(
lb
+
1
));
}
else
{
assert
(
!
"Unreachable"
);
return
-
1
;
...
...
@@ -232,12 +232,12 @@ per__long_range(long lb, long ub, unsigned long *range_r) {
}
int
per_
long_range_rebase
(
long
v
,
long
lb
,
long
ub
,
unsigned
long
*
output
)
{
u
nsigned
long
range
;
per_
imax_range_rebase
(
intmax_t
v
,
intmax_t
lb
,
intmax_t
ub
,
uintmax_t
*
output
)
{
u
intmax_t
range
;
assert
(
lb
<=
ub
);
if
(
v
<
lb
||
v
>
ub
||
per__
long
_range
(
lb
,
ub
,
&
range
)
<
0
)
{
if
(
v
<
lb
||
v
>
ub
||
per__
imax
_range
(
lb
,
ub
,
&
range
)
<
0
)
{
/* Range error. */
return
-
1
;
}
...
...
@@ -253,12 +253,12 @@ per_long_range_rebase(long v, long lb, long ub, unsigned long *output) {
*
output
=
v
-
lb
;
return
0
;
}
else
if
(
v
<
0
)
{
u
nsigned
long
rebased
=
1
+
(
unsigned
long
)
-
(
v
+
1
)
+
(
unsigned
long
)
lb
;
u
intmax_t
rebased
=
1
+
(
uintmax_t
)
-
(
v
+
1
)
+
(
uintmax_t
)
lb
;
assert
(
rebased
<=
range
);
/* By construction */
*
output
=
rebased
;
return
0
;
}
else
if
(
lb
<
0
)
{
u
nsigned
long
rebased
=
1
+
(
unsigned
long
)
-
(
lb
+
1
)
+
(
unsigned
long
)
v
;
u
intmax_t
rebased
=
1
+
(
uintmax_t
)
-
(
lb
+
1
)
+
(
uintmax_t
)
v
;
assert
(
rebased
<=
range
);
/* By construction */
*
output
=
rebased
;
return
0
;
...
...
@@ -269,10 +269,18 @@ per_long_range_rebase(long v, long lb, long ub, unsigned long *output) {
}
int
per_long_range_unrebase
(
unsigned
long
inp
,
long
lb
,
long
ub
,
long
*
outp
)
{
unsigned
long
range
;
per_long_range_rebase
(
long
v
,
intmax_t
lb
,
intmax_t
ub
,
unsigned
long
*
output
)
{
uintmax_t
tmp
=
*
output
;
int
rc
=
per_imax_range_rebase
((
intmax_t
)
v
,
lb
,
ub
,
&
tmp
);
*
output
=
tmp
;
return
rc
;
}
int
per_imax_range_unrebase
(
uintmax_t
inp
,
intmax_t
lb
,
intmax_t
ub
,
intmax_t
*
outp
)
{
uintmax_t
range
;
if
(
per__
long
_range
(
lb
,
ub
,
&
range
)
!=
0
)
{
if
(
per__
imax
_range
(
lb
,
ub
,
&
range
)
!=
0
)
{
return
-
1
;
}
...
...
@@ -285,15 +293,23 @@ per_long_range_unrebase(unsigned long inp, long lb, long ub, long *outp) {
return
-
1
;
}
if
(
inp
<=
LONG
_MAX
)
{
if
(
inp
<=
INTMAX
_MAX
)
{
*
outp
=
(
long
)
inp
+
lb
;
}
else
{
*
outp
=
(
lb
+
LONG_MAX
+
1
)
+
(
long
)((
inp
-
LONG
_MAX
)
-
1
);
*
outp
=
(
lb
+
INTMAX_MAX
+
1
)
+
(
intmax_t
)((
inp
-
INTMAX
_MAX
)
-
1
);
}
return
0
;
}
int
per_long_range_unrebase
(
unsigned
long
inp
,
intmax_t
lb
,
intmax_t
ub
,
long
*
outp
)
{
intmax_t
tmp
=
*
outp
;
int
rc
=
per_imax_range_unrebase
((
uintmax_t
)
inp
,
lb
,
ub
,
&
tmp
);
*
outp
=
tmp
;
return
rc
;
}
int32_t
aper_get_align
(
asn_per_data_t
*
pd
)
{
...
...
skeletons/per_support.h
View file @
51735138
...
...
@@ -24,8 +24,8 @@ typedef struct asn_per_constraint_s {
}
flags
;
int
range_bits
;
/* Full number of bits in the range */
int
effective_bits
;
/* Effective bits */
long
lower_bound
;
/* "lb" value */
long
upper_bound
;
/* "ub" value */
intmax_t
lower_bound
;
/* "lb" value */
intmax_t
upper_bound
;
/* "ub" value */
}
asn_per_constraint_t
;
typedef
struct
asn_per_constraints_s
{
asn_per_constraint_t
value
;
...
...
@@ -64,7 +64,7 @@ ssize_t uper_get_nsnnwn(asn_per_data_t *pd);
ssize_t
aper_get_nsnnwn
(
asn_per_data_t
*
pd
,
int
range
);
/* X.691-2008/11, #11.5.6 */
int
uper_get_constrained_whole_number
(
asn_per_data_t
*
pd
,
u
nsigned
long
*
v
,
int
nbits
);
int
uper_get_constrained_whole_number
(
asn_per_data_t
*
pd
,
u
intmax_t
*
v
,
int
nbits
);
/* Temporary compatibility layer. Will get removed. */
...
...
@@ -81,9 +81,11 @@ typedef struct asn_bit_outp_s asn_per_outp_t;
* -1: Conversion failed due to range problems.
* 0: Conversion was successful.
*/
int
per_long_range_rebase
(
long
v
,
long
lb
,
long
ub
,
unsigned
long
*
output
);
int
per_long_range_rebase
(
long
,
intmax_t
lb
,
intmax_t
ub
,
unsigned
long
*
output
);
int
per_imax_range_rebase
(
intmax_t
v
,
intmax_t
lb
,
intmax_t
ub
,
uintmax_t
*
output
);
/* The inverse operation: restores the value by the offset and its bounds. */
int
per_long_range_unrebase
(
unsigned
long
inp
,
long
lb
,
long
ub
,
long
*
outp
);
int
per_long_range_unrebase
(
unsigned
long
inp
,
intmax_t
lb
,
intmax_t
ub
,
long
*
outp
);
int
per_imax_range_unrebase
(
uintmax_t
inp
,
intmax_t
lb
,
intmax_t
ub
,
intmax_t
*
outp
);
/* X.691-2008/11, #11.5 */
int
uper_put_constrained_whole_number_u
(
asn_per_outp_t
*
po
,
unsigned
long
v
,
int
nbits
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment