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
6306aaff
Commit
6306aaff
authored
Sep 24, 2018
by
Mouse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Applied @brchiu partial fix for vlm#293 (still needs more testing, and a
similar fix for OCTET STRING)
parent
da3c61c5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
9 deletions
+43
-9
libasn1compiler/asn1c_C.c
libasn1compiler/asn1c_C.c
+41
-8
libasn1parser/asn1p_y.y
libasn1parser/asn1p_y.y
+2
-1
No files found.
libasn1compiler/asn1c_C.c
View file @
6306aaff
...
...
@@ -2386,6 +2386,21 @@ emit_default_string_value(arg_t *arg, asn1p_value_t *v) {
}
}
static
void
emit_default_bitstring_value
(
arg_t
*
arg
,
asn1p_value_t
*
v
)
{
OUT
(
"static const uint8_t defv[] = { "
);
assert
(
v
->
type
==
ATV_BITVECTOR
);
uint8_t
*
b
=
v
->
value
.
binary_vector
.
bits
;
for
(
int
i
=
0
;
i
<
(
v
->
value
.
binary_vector
.
size_in_bits
+
7
)
/
8
;
i
++
,
b
++
)
{
OUT
(
"0x%02x"
,
*
b
);
if
(
i
<
(
v
->
value
.
binary_vector
.
size_in_bits
+
7
)
/
8
-
1
)
OUT
(
", "
);
}
OUT
(
" };
\n
"
);
}
static
int
try_inline_default
(
arg_t
*
arg
,
asn1p_expr_t
*
expr
,
int
out
)
{
int
save_target
=
arg
->
target
->
target
;
...
...
@@ -2481,9 +2496,10 @@ try_inline_default(arg_t *arg, asn1p_expr_t *expr, int out) {
//expr->marker.flags &= ~EM_INDIRECT;
return
0
;
default:
if
(
etype
&
ASN_STRING_KM_MASK
)
{
if
(
expr
->
marker
.
default_value
==
NULL
||
expr
->
marker
.
default_value
->
type
!=
ATV_STRING
)
if
(
expr
->
marker
.
default_value
)
{
if
(
!
(
etype
&
ASN_STRING_KM_MASK
)
&&
(
expr
->
marker
.
default_value
->
type
!=
ATV_STRING
)
&&
(
expr
->
marker
.
default_value
->
type
!=
ATV_BITVECTOR
))
break
;
if
(
!
out
)
{
if
(
C99_MODE
)
OUT
(
".default_value_cmp = "
);
...
...
@@ -2501,15 +2517,23 @@ try_inline_default(arg_t *arg, asn1p_expr_t *expr, int out) {
OUT
(
"static int asn_DFL_%d_cmp(const void *sptr) {
\n
"
,
expr
->
_type_unique_index
);
INDENT
(
+
1
);
emit_default_string_value
(
arg
,
expr
->
marker
.
default_value
);
if
(
expr
->
marker
.
default_value
->
type
==
ATV_STRING
)
emit_default_string_value
(
arg
,
expr
->
marker
.
default_value
);
else
emit_default_bitstring_value
(
arg
,
expr
->
marker
.
default_value
);
OUT
(
"const %s *st = sptr;
\n
"
,
asn1c_type_name
(
arg
,
expr
,
TNF_CTYPE
));
OUT
(
"
\n
"
);
OUT
(
"if(!st) {
\n
"
);
OUT
(
"
\t
return -1; /* No value is not a default value */
\n
"
);
OUT
(
"}
\n
"
);
OUT
(
"
\n
"
);
OUT
(
"if(st->size == (sizeof(defv) - 1)
\n
"
);
OUT
(
"&& memcmp(st->buf, &defv, sizeof(defv) - 1) == 0)
\n
"
);
if
(
expr
->
marker
.
default_value
->
type
==
ATV_STRING
)
{
OUT
(
"if(st->size == (sizeof(defv) - 1)
\n
"
);
OUT
(
"&& memcmp(st->buf, &defv, sizeof(defv) - 1) == 0)
\n
"
);
}
else
{
OUT
(
"if(st->size == (sizeof(defv))
\n
"
);
OUT
(
"&& memcmp(st->buf, &defv, sizeof(defv)) == 0)
\n
"
);
}
OUT
(
"
\t
return 0;
\n
"
);
OUT
(
"return 1;
\n
"
);
INDENT
(
-
1
);
...
...
@@ -2518,7 +2542,10 @@ try_inline_default(arg_t *arg, asn1p_expr_t *expr, int out) {
OUT
(
"static int asn_DFL_%d_set(void **sptr) {
\n
"
,
expr
->
_type_unique_index
);
INDENT
(
+
1
);
emit_default_string_value
(
arg
,
expr
->
marker
.
default_value
);
if
(
expr
->
marker
.
default_value
->
type
==
ATV_STRING
)
emit_default_string_value
(
arg
,
expr
->
marker
.
default_value
);
else
emit_default_bitstring_value
(
arg
,
expr
->
marker
.
default_value
);
OUT
(
"%s *st = *sptr;
\n
"
,
asn1c_type_name
(
arg
,
expr
,
TNF_CTYPE
));
OUT
(
"uint8_t *nstr = MALLOC(sizeof(defv));
\n
"
);
OUT
(
"
\n
"
);
...
...
@@ -2532,7 +2559,13 @@ try_inline_default(arg_t *arg, asn1p_expr_t *expr, int out) {
OUT
(
"
\t
if(!st) { FREEMEM(nstr); return -1; }
\n
"
);
OUT
(
"}
\n
"
);
OUT
(
"st->buf = nstr;
\n
"
);
OUT
(
"st->size = sizeof(defv) - 1;
\n
"
);
if
(
expr
->
marker
.
default_value
->
type
==
ATV_STRING
)
{
OUT
(
"st->size = sizeof(defv) - 1;
\n
"
);
}
else
{
OUT
(
"st->size = sizeof(defv);
\n
"
);
if
(
etype
==
ASN_BASIC_BIT_STRING
)
OUT
(
"st->bits_unused = %d;
\n
"
,
(
8
-
expr
->
marker
.
default_value
->
value
.
binary_vector
.
size_in_bits
%
8
)
%
8
);
}
OUT
(
"
\n
"
);
OUT
(
"return 0;
\n
"
);
INDENT
(
-
1
);
...
...
libasn1parser/asn1p_y.y
View file @
6306aaff
...
...
@@ -2525,9 +2525,10 @@ _convert_bitstring2binary(char *str, int base) {
memlen = slen / (8 / baselen); /* Conservative estimate */
bv_ptr = binary_vector = malloc(memlen + 1);
if(bv_ptr == NULL)
if(bv_ptr == NULL)
{
/* ENOMEM */
return NULL;
}
cur_val = 0;
bits = 0;
...
...
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