Skip to content

Commit

Permalink
Fix version brackets in CHOICE
Browse files Browse the repository at this point in the history
Quote from Rec. ITU-T X.691 (02/2021) end of section 23:
"NOTE – Version brackets in the definition of choice extension
additions have no effect on how "ExtensionAdditionAlternatives"
are encoded."

In other words elements inside version brackets should not be grouped
together for CHOICE (as opposed to how its done for SEQUENCE).
  • Loading branch information
johvik authored and mouse07410 committed Feb 9, 2025
1 parent a20d29a commit 8baade5
Show file tree
Hide file tree
Showing 4 changed files with 548 additions and 12 deletions.
8 changes: 0 additions & 8 deletions libasn1compiler/asn1c_C.c
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,6 @@ asn1c_lang_C_type_CHOICE(arg_t *arg) {
asn1p_expr_t *expr = arg->expr;
asn1p_expr_t *v;
int saved_target = arg->target->target;
int ext_num = 1;

DEPENDENCIES;

Expand All @@ -994,13 +993,6 @@ asn1c_lang_C_type_CHOICE(arg_t *arg) {
continue;
}

if((v->expr_type == ASN_CONSTR_SEQUENCE) &&
(v->marker.flags & EM_OPTIONAL) &&
(v->Identifier == NULL)) {
char ext_name[20];
sprintf(ext_name, "ext%d", ext_num++);
v->Identifier = strdup(ext_name);
}
OUT("%s", c_presence_name(arg, v));
}
OUT("\n");
Expand Down
6 changes: 2 additions & 4 deletions libasn1parser/asn1p_y.y
Original file line number Diff line number Diff line change
Expand Up @@ -1097,10 +1097,8 @@ AlternativeTypeLists:
}
| AlternativeTypeLists ',' TOK_VBracketLeft AlternativeTypeLists TOK_VBracketRight {
$$ = $1;
$4->meta_type = AMT_TYPE;
$4->expr_type = ASN_CONSTR_SEQUENCE;
$4->marker.flags |= EM_OPTIONAL;
asn1p_expr_add($$, $4);
asn1p_expr_add_many($$, $4);
asn1p_expr_free($4);
}
;

Expand Down
31 changes: 31 additions & 0 deletions tests/tests-asn1c-compiler/165-choice-extended-group-OK.asn1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

-- OK: Everything is fine

-- iso.org.dod.internet.private.enterprise (1.3.6.1.4.1)
-- .spelio.software.asn1c.test (9363.1.5.1)
-- .165

ModuleTestExtensibleChoice
{ iso org(3) dod(6) internet(1) private(4) enterprise(1)
spelio(9363) software(1) asn1c(5) test(1) 165 }
DEFINITIONS AUTOMATIC TAGS ::=
BEGIN

Choice ::= CHOICE {
a INTEGER,
...,
b INTEGER,
[[
c INTEGER
]],
[[
d INTEGER,
e INTEGER
]],
[[
f INTEGER,
g INTEGER
]]
}

END
Loading

0 comments on commit 8baade5

Please sign in to comment.