From dc4376dc2f05d3922b93afe1ae19ba7fb63673ac Mon Sep 17 00:00:00 2001
From: Lev Walkin <vlm@lionet.info>
Date: Thu, 16 Mar 2006 11:04:55 +0000
Subject: [PATCH] more advanced stuff with defaults

---
 libasn1fix/asn1fix_cws.c      |  7 +++---
 libasn1fix/asn1fix_derefv.c   | 13 +++++++++++
 libasn1fix/asn1fix_retrieve.c |  3 ++-
 tests/99-class-sample-OK.asn1 | 42 +++++++++++++++++++++++++++++++++++
 4 files changed, 60 insertions(+), 5 deletions(-)
 create mode 100644 tests/99-class-sample-OK.asn1

diff --git a/libasn1fix/asn1fix_cws.c b/libasn1fix/asn1fix_cws.c
index 3d7b8aa7..e19071d9 100644
--- a/libasn1fix/asn1fix_cws.c
+++ b/libasn1fix/asn1fix_cws.c
@@ -138,11 +138,9 @@ _asn1f_parse_class_object_data(arg_t *arg, asn1p_expr_t *eclass,
 				chunk->content.token,
 				buf, p - buf);
 			ret = _asn1f_assign_cell_value(arg, row, cell, buf, p);
-			if(ret) {
-				if(newpos) *newpos = buf;
-				return ret;
-			}
+			if(ret) return ret;
 			buf = p;
+			if(newpos) *newpos = buf;
 		    } break;
 		case WC_OPTIONALGROUP: {
 			uint8_t *np = 0;
@@ -152,6 +150,7 @@ _asn1f_parse_class_object_data(arg_t *arg, asn1p_expr_t *eclass,
 			if(newpos) *newpos = np;
 			if(ret && np != buf)
 				return ret;
+			buf = np;
 		    } break;
 		}
 	}
diff --git a/libasn1fix/asn1fix_derefv.c b/libasn1fix/asn1fix_derefv.c
index 76f49a39..5436d58b 100644
--- a/libasn1fix/asn1fix_derefv.c
+++ b/libasn1fix/asn1fix_derefv.c
@@ -38,6 +38,19 @@ asn1f_fix_dereference_defaults(arg_t *arg) {
 			break;
 		}
 
+
+		if(expr->expr_type == A1TC_CLASSFIELD_FTVFS) {
+			asn1p_expr_t *child = TQ_FIRST(&expr->members);
+			int ret;
+			assert(child);
+			assert(child->marker.default_value == 0);
+			tmparg.expr = child;
+			child->marker.default_value=expr->marker.default_value;
+			ret = asn1f_fix_dereference_defaults(&tmparg);
+			expr->marker.default_value = child->marker.default_value;
+			if(ret == 0) return 0;	/* Finished */
+		}
+
 		tmparg.expr = &tmpexpr;
 		tmpexpr.meta_type = AMT_VALUE;
 		tmpexpr.marker.default_value = 0;
diff --git a/libasn1fix/asn1fix_retrieve.c b/libasn1fix/asn1fix_retrieve.c
index 161e0da1..ae3042d9 100644
--- a/libasn1fix/asn1fix_retrieve.c
+++ b/libasn1fix/asn1fix_retrieve.c
@@ -248,7 +248,8 @@ asn1f_lookup_symbol(arg_t *arg, asn1p_module_t *mod, asn1p_ref_t *ref) {
 		}
 
 		expr = asn1f_lookup_symbol(arg, imports_from, &tmpref);
-		if(!expr && !(arg->expr->_mark & TM_BROKEN)) {
+		if(!expr && !(arg->expr->_mark & TM_BROKEN)
+		&& !(imports_from->_tags & MT_STANDARD_MODULE)) {
 			arg->expr->_mark |= TM_BROKEN;
 			if(modulename) {
 				FATAL("Module %s referred by %s in module %s "
diff --git a/tests/99-class-sample-OK.asn1 b/tests/99-class-sample-OK.asn1
new file mode 100644
index 00000000..aa9d5947
--- /dev/null
+++ b/tests/99-class-sample-OK.asn1
@@ -0,0 +1,42 @@
+
+-- OK: Everything is fine
+
+-- iso.org.dod.internet.private.enterprise (1.3.6.1.4.1)
+-- .spelio.software.asn1c.test (9363.1.5.1)
+-- .99
+
+ModuleClassSample
+	{ iso org(3) dod(6) internet (1) private(4) enterprise(1)
+		spelio(9363) software(1) asn1c(5) test(1) 99 }
+	DEFINITIONS ::=
+BEGIN
+
+	SAMPLE-CLASS ::= CLASS {
+		&id	RELATIVE-OID UNIQUE,
+		&code	ENUMERATED { request, response, status }
+				DEFAULT request,
+		&Type	OPTIONAL
+	} WITH SYNTAX { [TYPE &Type] [WITH CODE &code] IDENTIFIED BY &id }
+
+	request-Whatever SAMPLE-CLASS
+		::= { IDENTIFIED BY request-whatever }
+
+	respond-Stuff SAMPLE-CLASS
+		::= { WITH CODE 1 IDENTIFIED BY response-stuff }
+
+	request-Status SAMPLE-CLASS
+		::= { TYPE SampleType WITH CODE 2 IDENTIFIED BY request-id }
+
+	request-Salt SAMPLE-CLASS
+		::= { TYPE Salt IDENTIFIED BY request-salt }
+
+	request-id RELATIVE-OID ::= { 1 1 1 }
+	request-salt RELATIVE-OID ::= { 1 1 1 }
+	request-whatever RELATIVE-OID ::= { 1 1 5 }
+	response-stuff RELATIVE-OID ::= { 2 0 1 }
+
+
+	SampleType ::= SEQUENCE { ... }
+	Salt ::= SET { ... }
+
+END
-- 
GitLab