Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate enumerations. #121

Open
wants to merge 1 commit into
base: vlm_master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions libasn1compiler/asn1c_C.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,21 @@ asn1c_lang_C_type_common_INTEGER(arg_t *arg) {
if(map_extensions)
OUT("\t/* This list is extensible */\n");
OUT("};\n");

OUT("static int asn_validate_%s(const asn_TYPE_descriptor_t *td,\n", MKID(expr));
OUT(" const void *sptr,\n");
OUT(" asn_app_constraint_failed_f *ctfailcb,\n");
OUT(" void* app_key) {\n");
OUT(" if(! sptr) { return -1; }\n");
OUT(" e_%s value = *(e_%s*)sptr;\n", MKID(expr), MKID(expr));
OUT(" switch(value) {\n");
for(eidx = 0; eidx < el_count; eidx++) {
OUT(" case %s_%s:\n", MKID(expr), v2e[eidx].name);
}
OUT(" return 0;\n");
OUT(" }\n");
OUT(" return -1;\n");
OUT("}\n");
arg->param.localvalidation = 1;
OUT("static const unsigned int asn_MAP_%s_enum2value_%d[] = {\n",
MKID(expr), expr->_type_unique_index);
qsort(v2e, el_count, sizeof(v2e[0]), compar_enumMap_byName);
Expand Down Expand Up @@ -3185,18 +3199,16 @@ emit_type_DEF(arg_t *arg, asn1p_expr_t *expr, enum tvm_compat tv_mode, int tags_
OUT("_" #foo ""); \
} while(0)

#define FUNCREF2(foo) \
do { \
OUT("%s", p2); \
OUT("_" #foo); \
} while(0)

if (arg->flags & A1C_NO_CONSTRAINTS) {
OUT("0");
} else {
if (!expr->combined_constraints)
FUNCREF2(constraint);
else
if (!expr->combined_constraints) {
if(arg->param.localvalidation == 1)
OUT("asn_validate_%s", p);
else
OUT("%s_constraint", p2);
arg->param.localvalidation = 0;
} else
FUNCREF(constraint);
}
OUT("\n");
Expand Down
3 changes: 3 additions & 0 deletions libasn1compiler/asn1c_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ typedef struct arg_s {
asn1p_expr_t *expr;

int embed;
union {
int localvalidation;
} param;
} arg_t;

/*
Expand Down
4 changes: 2 additions & 2 deletions libasn1compiler/asn1compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static int asn1c_detach_streams(asn1p_expr_t *expr);
int
asn1_compile(asn1p_t *asn, const char *datadir, const char *destdir, enum asn1c_flags flags,
int argc, int optc, char **argv) {
arg_t arg_s;
arg_t arg_s = {0};
arg_t *arg = &arg_s;
asn1p_module_t *mod;
int ret;
Expand Down Expand Up @@ -242,7 +242,7 @@ asn1c_debug_expr_naming(arg_t *arg) {
void
asn1c_debug_type_naming(asn1p_t *asn, enum asn1c_flags flags,
char **asn_type_names) {
arg_t arg_s;
arg_t arg_s = {0};
arg_t *arg = &arg_s;
asn1p_module_t *mod;

Expand Down