diff options
author | Santiago Carot-Nemesio <sancane@gmail.com> | 2011-04-22 13:21:33 +0200 |
---|---|---|
committer | Santiago Carot-Nemesio <sancane@gmail.com> | 2011-04-22 14:00:08 +0200 |
commit | 8da8e73f1800d518955141e50be9811608dae011 (patch) | |
tree | d46435e3d5bacb85998bd1190af2665fa7359d12 /libasn1compiler | |
parent | cf6c1e230213a3b90d476437ff8667040842e889 (diff) |
Fix compilation warning in generated check constraints function.
Integer types defined in ASN1 in the range (0..4294967295) does
not need declare the variable "value". Before this patch, generated
code produced an unnecessary variable assignation and new compilers
trigger a message warning because the variable is no longer used
anymore due to the optimization for unsigned longs check.
Diffstat (limited to 'libasn1compiler')
-rw-r--r-- | libasn1compiler/asn1c_constraint.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/libasn1compiler/asn1c_constraint.c b/libasn1compiler/asn1c_constraint.c index 2b1420e8..e9d796de 100644 --- a/libasn1compiler/asn1c_constraint.c +++ b/libasn1compiler/asn1c_constraint.c @@ -14,6 +14,16 @@ static asn1p_expr_type_e _find_terminal_type(arg_t *arg); static int emit_range_comparison_code(arg_t *arg, asn1cnst_range_t *range, const char *varname, asn1c_integer_t natural_start, asn1c_integer_t natural_stop); static int native_long_sign(asn1cnst_range_t *r); /* -1, 0, 1 */ +static int +ulong_optimization(asn1p_expr_type_e etype, asn1cnst_range_t *r_size, + asn1cnst_range_t *r_value) +{ + return (!r_size && r_value + && (etype == ASN_BASIC_INTEGER + || etype == ASN_BASIC_ENUMERATED) + && native_long_sign(r_value) == 0); +} + int asn1c_emit_constraint_checking_code(arg_t *arg) { asn1cnst_range_t *r_size; @@ -24,6 +34,7 @@ asn1c_emit_constraint_checking_code(arg_t *arg) { int got_something = 0; int alphabet_table_compiled; int produce_st = 0; + int ulong_optimize = 0; ct = expr->combined_constraints; if(ct == NULL) @@ -93,7 +104,10 @@ asn1c_emit_constraint_checking_code(arg_t *arg) { case ASN_BASIC_INTEGER: case ASN_BASIC_ENUMERATED: if(native_long_sign(r_value) >= 0) { - OUT("unsigned long value;\n"); + ulong_optimize = ulong_optimization(etype, r_size, r_value); + if(!ulong_optimize) { + OUT("unsigned long value;\n"); + } } else { OUT("long value;\n"); } @@ -124,7 +138,7 @@ asn1c_emit_constraint_checking_code(arg_t *arg) { OUT("}\n"); OUT("\n"); - if(r_value) + if((r_value) && (!ulong_optimize)) emit_value_determination_code(arg, etype, r_value); if(r_size) emit_size_determination_code(arg, etype); @@ -140,10 +154,7 @@ asn1c_emit_constraint_checking_code(arg_t *arg) { /* * Optimization for unsigned longs. */ - if(!r_size && r_value - && (etype == ASN_BASIC_INTEGER - || etype == ASN_BASIC_ENUMERATED) - && native_long_sign(r_value) == 0) { + if(ulong_optimize) { OUT("\n"); OUT("/* Constraint check succeeded */\n"); OUT("return 0;\n"); |