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
0995f351
Commit
0995f351
authored
Sep 17, 2017
by
Lev Walkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get rid of undefined behavior
parent
beedbdeb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
21 deletions
+26
-21
skeletons/OBJECT_IDENTIFIER.c
skeletons/OBJECT_IDENTIFIER.c
+6
-3
tests/tests-skeletons/check-OIDs.c
tests/tests-skeletons/check-OIDs.c
+20
-18
No files found.
skeletons/OBJECT_IDENTIFIER.c
View file @
0995f351
...
...
@@ -80,7 +80,6 @@ OBJECT_IDENTIFIER_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
return
0
;
}
int
OBJECT_IDENTIFIER_get_single_arc
(
const
uint8_t
*
arcbuf
,
unsigned
int
arclen
,
signed
int
add
,
void
*
rvbufp
,
unsigned
int
rvsize
)
{
unsigned
LE
GCC_NOTUSED
=
1
;
/* Little endian (x86) */
...
...
@@ -93,6 +92,8 @@ OBJECT_IDENTIFIER_get_single_arc(const uint8_t *arcbuf, unsigned int arclen, sig
rvsize
*=
CHAR_BIT
;
/* bytes to bits */
arclen
*=
7
;
/* bytes to bits */
assert
(
add
<=
0
);
/*
* The arc has the number of bits
* cannot be represented using supplied return value type.
...
...
@@ -133,11 +134,13 @@ OBJECT_IDENTIFIER_get_single_arc(const uint8_t *arcbuf, unsigned int arclen, sig
/* Gather all bits into the accumulator */
for
(
accum
=
cache
;
arcbuf
<
arcend
;
arcbuf
++
)
accum
=
(
accum
<<
7
)
|
(
*
arcbuf
&
~
0x80
);
if
(
accum
<
(
unsigned
)
-
add
)
{
if
(
accum
<
(
unsigned
)
-
add
||
accum
>
(
ULONG_MAX
-
(
unsigned
long
)(
-
add
)))
{
errno
=
ERANGE
;
/* Overflow */
return
-
1
;
}
*
(
unsigned
long
*
)(
void
*
)
rvbuf
=
accum
+
add
;
/* alignment OK! */
*
(
unsigned
long
*
)(
void
*
)
rvbuf
=
accum
-
(
unsigned
long
)(
-
add
);
/* alignment OK! */
return
0
;
}
...
...
tests/tests-skeletons/check-OIDs.c
View file @
0995f351
...
...
@@ -13,14 +13,14 @@ _print(const void *buffer, size_t size, void *app_key) {
}
static
void
check_OID
(
uint8_t
*
buf
,
size_t
len
,
int
*
ck_buf
,
int
ck_len
)
{
check_OID
(
int
lineno
,
uint8_t
*
buf
,
size_t
len
,
int
*
ck_buf
,
int
ck_len
)
{
OBJECT_IDENTIFIER_t
*
oid
;
asn_dec_rval_t
rval
;
unsigned
long
arcs
[
10
];
int
alen
;
int
i
;
printf
(
"
Checking {"
);
printf
(
"
%03d: Checking {"
,
lineno
);
for
(
i
=
0
;
i
<
(
int
)
len
;
i
++
)
{
printf
(
"%s%02x"
,
i
?
" "
:
""
,
buf
[
i
]);
}
printf
(
"} against {"
);
for
(
i
=
0
;
i
<
ck_len
;
i
++
)
{
printf
(
"%s%d"
,
i
?
" "
:
""
,
ck_buf
[
i
]);
}
...
...
@@ -60,14 +60,14 @@ check_OID(uint8_t *buf, size_t len, int *ck_buf, int ck_len) {
}
static
void
check_ROID
(
uint8_t
*
buf
,
size_t
len
,
int
*
ck_buf
,
int
ck_len
)
{
check_ROID
(
int
lineno
,
uint8_t
*
buf
,
size_t
len
,
int
*
ck_buf
,
int
ck_len
)
{
RELATIVE_OID_t
*
oid
;
asn_dec_rval_t
rval
;
unsigned
long
arcs
[
10
];
int
alen
;
int
i
;
printf
(
"
Checking {"
);
printf
(
"
%03d: Checking {"
,
lineno
);
for
(
i
=
0
;
i
<
(
ssize_t
)
len
;
i
++
)
{
printf
(
"%s%02x"
,
i
?
" "
:
""
,
buf
[
i
]);
}
printf
(
"} against {"
);
for
(
i
=
0
;
i
<
ck_len
;
i
++
)
{
printf
(
"%s%d"
,
i
?
" "
:
""
,
ck_buf
[
i
]);
}
...
...
@@ -107,7 +107,7 @@ check_ROID(uint8_t *buf, size_t len, int *ck_buf, int ck_len) {
* Encode the specified array of arcs as RELATIVE-OID, decode it and compare.
*/
static
void
check_REGEN
(
int
*
arcs
,
int
acount
)
{
check_REGEN
(
int
lineno
,
int
*
arcs
,
int
acount
)
{
static
RELATIVE_OID_t
oid
;
unsigned
long
tmp_arcs
[
10
];
int
tmp_alen
=
10
;
...
...
@@ -116,7 +116,7 @@ check_REGEN(int *arcs, int acount) {
int
i
;
if
(
0
)
{
fprintf
(
stderr
,
"
Encoding (R) {"
);
fprintf
(
stderr
,
"
%03d: Encoding (R) {"
,
lineno
);
for
(
i
=
0
;
i
<
acount
;
i
++
)
{
fprintf
(
stderr
,
" %u"
,
arcs
[
i
]);
}
...
...
@@ -149,7 +149,7 @@ check_REGEN(int *arcs, int acount) {
* decode it and compare.
*/
static
void
check_REGEN_OID
(
int
*
arcs
,
int
acount
)
{
check_REGEN_OID
(
int
lineno
,
int
*
arcs
,
int
acount
)
{
static
OBJECT_IDENTIFIER_t
oid
;
unsigned
long
tmp_arcs
[
10
];
int
tmp_alen
=
10
;
...
...
@@ -158,7 +158,7 @@ check_REGEN_OID(int *arcs, int acount) {
int
i
;
if
(
0
)
{
fprintf
(
stderr
,
"
Encoding (O) {"
);
fprintf
(
stderr
,
"
%03d: Encoding (O) {"
,
lineno
);
for
(
i
=
0
;
i
<
acount
;
i
++
)
{
fprintf
(
stderr
,
" %u"
,
arcs
[
i
]);
}
...
...
@@ -274,16 +274,18 @@ static void check_xer(int expect_arcs, char *xer) {
assert
(
ret
==
expect_arcs
);
}
#define CHECK_OID(n) check_OID(buf ## n, sizeof(buf ## n), \
buf ## n ## _check, \
sizeof(buf ## n ## _check)/sizeof(buf ## n ## _check[0]))
#define CHECK_ROID(n) check_ROID(buf ## n, sizeof(buf ## n), \
buf ## n ## _check, \
sizeof(buf ## n ## _check)/sizeof(buf ## n ## _check[0]))
#define CHECK_REGEN(n) check_REGEN(buf ## n ## _check, \
sizeof(buf ## n ## _check)/sizeof(buf ## n ## _check[0]))
#define CHECK_REGEN_OID(n) check_REGEN_OID(buf ## n ## _check, \
sizeof(buf ## n ## _check)/sizeof(buf ## n ## _check[0]))
#define CHECK_OID(n) \
check_OID(__LINE__, buf##n, sizeof(buf##n), buf##n##_check, \
sizeof(buf##n##_check) / sizeof(buf##n##_check[0]))
#define CHECK_ROID(n) \
check_ROID(__LINE__, buf##n, sizeof(buf##n), buf##n##_check, \
sizeof(buf##n##_check) / sizeof(buf##n##_check[0]))
#define CHECK_REGEN(n) \
check_REGEN(__LINE__, buf##n##_check, \
sizeof(buf##n##_check) / sizeof(buf##n##_check[0]))
#define CHECK_REGEN_OID(n) \
check_REGEN_OID(__LINE__, buf##n##_check, \
sizeof(buf##n##_check) / sizeof(buf##n##_check[0]))
int
main
()
{
...
...
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