aboutsummaryrefslogtreecommitdiffstats
path: root/libasn1fix/asn1fix_derefv.c
blob: 7be9d6d2d6f92e8f4f0309508cc6a06fe323d09c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "asn1fix_internal.h"

/*
 * Dereference DefinedValues:
 */
int
asn1f_fix_dereference_values(arg_t *arg) {
	asn1p_expr_t *expr = arg->expr;
	int r_value = 0;

	if(expr->meta_type != AMT_VALUE)
		return 0;	/* Just ignore it */

	if(expr->value == NULL)
		return 0;	/* Just ignore it */

	if(expr->value && expr->value->type != ATV_REFERENCED)
		return 0;	/* Not a reference */

	DEBUG("%s(%s %x ::= %s) for line %d", __func__,
		expr->Identifier, expr->expr_type,
		asn1f_printable_value(expr->value), expr->_lineno);

	/*
	 * If this integer has a value, check that this value
	 * is an integer. If it is a reference, resolve it.
	 */
	if(expr->value) {

		if(asn1f_value_resolve(arg, expr)) {
			/* This function will emit messages */
			r_value = -1;
		}

		if(expr->value->type != ATV_INTEGER) {
			FATAL(
				"INTEGER value %s at line %d: "
				"Incompatible value specified: %s",
				expr->Identifier,
				expr->_lineno,
				asn1f_printable_value(expr->value)
			);
			r_value = -1;
		}
	} else {
		FATAL("Value of \"%s\" at line %d: "
			"Incompatible value specified",
			expr->Identifier,
			expr->_lineno
		);
		r_value = -1;
	}

	return r_value;
}