From 63b4126c098ac7bbd0f1a4bb90866179fa1bf21a Mon Sep 17 00:00:00 2001 From: Lev Walkin Date: Tue, 6 Nov 2007 01:48:46 +0000 Subject: C90-compliant negative LONG_MIN --- libasn1compiler/asn1c_C.c | 17 +++++++++-------- libasn1compiler/asn1c_constraint.c | 22 +++++++++++----------- libasn1compiler/asn1c_out.h | 17 +++++++++++++++++ 3 files changed, 37 insertions(+), 19 deletions(-) (limited to 'libasn1compiler') diff --git a/libasn1compiler/asn1c_C.c b/libasn1compiler/asn1c_C.c index ef0c8688..e2b4401a 100644 --- a/libasn1compiler/asn1c_C.c +++ b/libasn1compiler/asn1c_C.c @@ -1859,8 +1859,7 @@ emit_single_member_PER_constraint(arg_t *arg, asn1cnst_range_t *range, int alpha if(lv > 0x7fffffff) { lv = 0x7fffffff; gcmt++; } if(rv > 0x7fffffff) { rv = 0x7fffffff; gcmt++; } if(gcmt) { - OUT("% " PRIdASN ", % " PRIdASN " }", - lv, rv); + OINTS(lv); OUT(", "); OINTS(rv); OUT(" }"); goto pcmt; } } @@ -1872,8 +1871,8 @@ emit_single_member_PER_constraint(arg_t *arg, asn1cnst_range_t *range, int alpha OUT("{ APC_SEMI_CONSTRAINED,\t-1, -1, "); } } - OUT("% " PRIdASN ", % " PRIdASN " }", - range->left.value, range->right.value); + OINTS(range->left.value); OUT(", "); + OINTS(range->right.value); OUT(" }"); } else { OUT("{ APC_UNCONSTRAINED,\t-1, -1, 0, 0 }"); } @@ -2129,12 +2128,14 @@ try_inline_default(arg_t *arg, asn1p_expr_t *expr, int out) { OUT("/* Install default value %" PRIdASN " */\n", expr->marker.default_value->value.v_integer); if(fits_long) { - OUT("*st = %" PRIdASN ";\n", - expr->marker.default_value->value.v_integer); + OUT("*st = "); + OINT(expr->marker.default_value->value.v_integer); + OUT(";\n"); OUT("return 0;\n"); } else { - OUT("return asn_long2INTEGER(st, %" PRIdASN ");\n", - expr->marker.default_value->value.v_integer); + OUT("return asn_long2INTEGER(st, "); + OINT(expr->marker.default_value->value.v_integer); + OUT(");\n"); } INDENT(-1); OUT("} else {\n"); diff --git a/libasn1compiler/asn1c_constraint.c b/libasn1compiler/asn1c_constraint.c index 1e2efa45..ea9df803 100644 --- a/libasn1compiler/asn1c_constraint.c +++ b/libasn1compiler/asn1c_constraint.c @@ -495,20 +495,20 @@ emit_range_comparison_code(arg_t *arg, asn1cnst_range_t *range, const char *varn } if(ignore_left) { - OUT("%s <= %" PRIdASN, varname, - r->right.value); + OUT("%s <= ", varname); + OINT(r->right.value); } else if(ignore_right) { - OUT("%s >= %" PRIdASN, varname, - r->left.value); + OUT("%s >= ", varname); + OINT(r->left.value); } else if(r->left.value == r->right.value) { - OUT("%s == %" PRIdASN, varname, - r->right.value); + OUT("%s == ", varname); + OINT(r->right.value); } else { - OUT("%s >= %" PRIdASN " && %s <= %" PRIdASN, - varname, - r->left.value, - varname, - r->right.value); + OUT("%s >= ", varname); + OINT(r->left.value); + OUT(" && "); + OUT("%s <= ", varname); + OINT(r->right.value); } if(r != range) OUT(")"); generated_something = 1; diff --git a/libasn1compiler/asn1c_out.h b/libasn1compiler/asn1c_out.h index 0523cbcf..04d7ff2f 100644 --- a/libasn1compiler/asn1c_out.h +++ b/libasn1compiler/asn1c_out.h @@ -108,4 +108,21 @@ int asn1c_compiled_output(arg_t *arg, const char *fmt, ...); REDIR(saved_target); \ } while(0) +/* + * Format LONG_MIN according to C90 rules. + */ +#define OINT(iv) do { \ + if(iv == (-2147483647L - 1)) \ + OUT("(-2147483647L - 1)"); \ + else \ + OUT("%" PRIdASN, iv); \ +} while(0) + +#define OINTS(iv) do { \ + if(iv == (-2147483647L - 1)) \ + OUT("(-2147483647L - 1)"); \ + else \ + OUT("% " PRIdASN, iv); \ +} while(0) + #endif /* _ASN1_COMPILED_OUTPUT_H_ */ -- cgit v1.2.3