Skip to content

Commit ac1e6ee

Browse files
authored
Merge pull request #460 from mouse07410/copilot/fix-complex-threshold-variable
Move complex_threshold from global to arg_t structure
2 parents e948c6f + 39b98e4 commit ac1e6ee

File tree

6 files changed

+935
-7
lines changed

6 files changed

+935
-7
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
1.3.2:
22
FIXES:
3+
* Moved complex_threshold from global variable to arg_t structure field.
4+
Applications linking to libasn1compiler no longer need to define their own
5+
version of the global complex_threshold variable. The variable is now properly
6+
encapsulated within the compiler's argument structure and passed through the
7+
asn1_compile() function. Default threshold value remains 4. Added test case
8+
for -fcomplex-threshold flag validation.
9+
(Severity: low; Security impact: none)
310
* Fixed JER OPEN TYPE decoder to comply with ITU-T X.697 Clause 41. The decoder
411
was incorrectly attempting to parse CHOICE-style key wrappers and consuming
512
parent SEQUENCE delimiters, causing "Unexpected JSON key" and "Out of defined

asn1c/asn1c.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ is_integer(const char *str, long *out_val) {
8484
static void usage(const char *av0); /* Print the Usage screen and exit */
8585
static int importStandardModules(asn1p_t *asn, const char *skeletons_dir);
8686

87-
int complex_threshold = 4; /* threshold after which complex_level is true (DIRTY HACK) */
87+
8888

8989
int
9090
main(int ac, char **av) {
@@ -105,6 +105,7 @@ main(int ac, char **av) {
105105
int ch; /* Command line character */
106106
int i; /* Index in some loops */
107107
int exit_code = 0; /* Exit code */
108+
int complex_threshold = 4; /* Threshold for switching structures to ptrs */
108109

109110
/*
110111
* Process command-line options.
@@ -492,7 +493,8 @@ main(int ac, char **av) {
492493
* of another language.
493494
*/
494495
if(asn1_compile(asn, skeletons_dir, destdir ? destdir : "",
495-
asn1_compiler_flags, ac + optind, optind, av - optind)) {
496+
asn1_compiler_flags, ac + optind, optind, av - optind,
497+
complex_threshold)) {
496498
exit_code = EX_SOFTWARE;
497499
}
498500

libasn1compiler/asn1c_C.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4426,7 +4426,6 @@ emit_include_dependencies(arg_t *arg) {
44264426
return 0;
44274427
}
44284428

4429-
extern int complex_threshold; // defined in asn1c/asn1c.c - need fixing
44304429
/*
44314430
* Check if it is better to make this type indirectly accessed via
44324431
* a pointer.
@@ -4516,10 +4515,11 @@ expr_break_recursion(arg_t *arg, asn1p_expr_t *expr) {
45164515
/* If the terminal has 4 or more complex members, use indirection
45174516
* to avoid excessive nesting and potential circular dependencies
45184517
* that might not be caught by simple recursion detection.
4519-
* This threshold is chosen to avoid breaking existing test expectations
4518+
* This threshold is configurable via -fcomplex-threshold flag
4519+
* (default: 4) and is chosen to avoid breaking existing test expectations
45204520
* while still handling deeply nested structures like F1AP's SRSConfig.
45214521
*/
4522-
if(complex_members >= complex_threshold) {
4522+
if(complex_members >= arg->complex_threshold) {
45234523
expr->marker.flags |= EM_INDIRECT;
45244524
expr->marker.flags |= EM_UNRECURSE;
45254525
return 1;

libasn1compiler/asn1compiler.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static void asn1c_mark_ioc_table_dependencies(arg_t *arg, asn1p_ioc_table_t *ioc
1616

1717
int
1818
asn1_compile(asn1p_t *asn, const char *datadir, const char *destdir, enum asn1c_flags flags,
19-
int argc, int optc, char **argv) {
19+
int argc, int optc, char **argv, int complex_threshold) {
2020
arg_t arg_s = {0};
2121
arg_t *arg = &arg_s;
2222
asn1p_module_t *mod;
@@ -35,6 +35,7 @@ asn1_compile(asn1p_t *asn, const char *datadir, const char *destdir, enum asn1c_
3535
arg->logger_cb = default_logger_cb;
3636
arg->flags = flags;
3737
arg->asn = asn;
38+
arg->complex_threshold = complex_threshold;
3839

3940
/*
4041
* If -flist-deps is specified, list dependencies and exit

libasn1compiler/asn1compiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ enum asn1c_flags {
144144
* Compile the ASN.1 specification.
145145
*/
146146
int asn1_compile(asn1p_t *asn, const char *datadir, const char *destdir, enum asn1c_flags,
147-
int argc, int optc, char **argv);
147+
int argc, int optc, char **argv, int complex_threshold);
148148

149149
void asn1c_debug_type_naming(asn1p_t *asn, enum asn1c_flags,
150150
char **asn_type_names);

0 commit comments

Comments
 (0)