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
a9e63373
Commit
a9e63373
authored
Sep 17, 2017
by
Lev Walkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove undefined behavior
parent
93180046
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
5 deletions
+27
-5
skeletons/NativeEnumerated_oer.c
skeletons/NativeEnumerated_oer.c
+26
-4
tests/tests-skeletons/check-OER-NativeEnumerated.c
tests/tests-skeletons/check-OER-NativeEnumerated.c
+1
-1
No files found.
skeletons/NativeEnumerated_oer.c
View file @
a9e63373
...
@@ -9,6 +9,30 @@
...
@@ -9,6 +9,30 @@
#include <NativeEnumerated.h>
#include <NativeEnumerated.h>
#include <errno.h>
#include <errno.h>
/*
* This function is only to get rid of Undefined Behavior Sanitizer warning.
*/
static
intmax_t
CLANG_NO_SANITIZE
(
"shift-base"
)
asn__safe_nativeenumerated_convert_helper
(
const
uint8_t
*
b
,
const
uint8_t
*
end
)
{
intmax_t
value
;
/* Perform the sign initialization */
/* Actually value = -(*b >> 7); gains nothing, yet unreadable! */
if
((
*
b
>>
7
))
{
value
=
-
1
;
}
else
{
value
=
0
;
}
/* Conversion engine */
for
(;
b
<
end
;
b
++
)
{
value
=
(
value
<<
8
)
|
*
b
;
}
return
value
;
}
asn_dec_rval_t
asn_dec_rval_t
NativeEnumerated_decode_oer
(
const
asn_codec_ctx_t
*
opt_codec_ctx
,
NativeEnumerated_decode_oer
(
const
asn_codec_ctx_t
*
opt_codec_ctx
,
asn_TYPE_descriptor_t
*
td
,
asn_TYPE_descriptor_t
*
td
,
...
@@ -42,7 +66,7 @@ NativeEnumerated_decode_oer(const asn_codec_ctx_t *opt_codec_ctx,
...
@@ -42,7 +66,7 @@ NativeEnumerated_decode_oer(const asn_codec_ctx_t *opt_codec_ctx,
*/
*/
size_t
length
=
*
b
&
0x7f
;
size_t
length
=
*
b
&
0x7f
;
const
uint8_t
*
bend
;
const
uint8_t
*
bend
;
long
value
;
intmax_t
value
;
if
(
length
<
1
||
length
>
sizeof
(
*
native
))
{
if
(
length
<
1
||
length
>
sizeof
(
*
native
))
{
ASN__DECODE_FAILED
;
ASN__DECODE_FAILED
;
...
@@ -52,10 +76,8 @@ NativeEnumerated_decode_oer(const asn_codec_ctx_t *opt_codec_ctx,
...
@@ -52,10 +76,8 @@ NativeEnumerated_decode_oer(const asn_codec_ctx_t *opt_codec_ctx,
}
}
b
++
;
b
++
;
bend
=
b
+
length
;
bend
=
b
+
length
;
value
=
(
*
b
&
0x80
)
?
-
1
:
0
;
/* Determine sign */
for
(;
b
<
bend
;
b
++
)
value
=
(
value
<<
8
)
|
*
b
;
value
=
asn__safe_nativeenumerated_convert_helper
(
b
,
bend
);
if
(
value
<
0
)
{
if
(
value
<
0
)
{
const
asn_INTEGER_specifics_t
*
specs
=
const
asn_INTEGER_specifics_t
*
specs
=
(
const
asn_INTEGER_specifics_t
*
)
td
->
specifics
;
(
const
asn_INTEGER_specifics_t
*
)
td
->
specifics
;
...
...
tests/tests-skeletons/check-OER-NativeEnumerated.c
View file @
a9e63373
...
@@ -182,7 +182,7 @@ main() {
...
@@ -182,7 +182,7 @@ main() {
CHECK_ROUNDTRIP
(
value
);
CHECK_ROUNDTRIP
(
value
);
}
}
for
(
size_t
i
=
0
;
i
<
8
*
sizeof
(
intmax_t
)
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
8
*
sizeof
(
intmax_t
)
-
1
;
i
++
)
{
intmax_t
value
=
(
intmax_t
)
1
<<
i
;
intmax_t
value
=
(
intmax_t
)
1
<<
i
;
CHECK_ROUNDTRIP
(
value
);
CHECK_ROUNDTRIP
(
value
);
value
=
-
value
;
value
=
-
value
;
...
...
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