aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlm <vlm@59561ff5-6e30-0410-9f3c-9617f08c8826>2007-11-06 01:48:46 +0000
committervlm <vlm@59561ff5-6e30-0410-9f3c-9617f08c8826>2007-11-06 01:48:46 +0000
commitfea6602591fa7bd899b9f875b327444536f8219c (patch)
tree153748b9f935c9997a23e8194d812c7a897f4ac6
parentf394b7f27430cd215407ad3ad647f1b696e6c01e (diff)
C90-compliant negative LONG_MIN
git-svn-id: https://asn1c.svn.sourceforge.net/svnroot/asn1c/trunk@1392 59561ff5-6e30-0410-9f3c-9617f08c8826
-rw-r--r--libasn1compiler/asn1c_C.c17
-rw-r--r--libasn1compiler/asn1c_constraint.c22
-rw-r--r--libasn1compiler/asn1c_out.h17
-rw-r--r--tests/90-cond-int-type-OK.asn1.-P6
-rw-r--r--tests/90-cond-int-type-OK.asn1.-Pfnative-types6
-rw-r--r--tests/90-cond-int-type-OK.asn1.-Pgen-PER12
6 files changed, 49 insertions, 31 deletions
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_ */
diff --git a/tests/90-cond-int-type-OK.asn1.-P b/tests/90-cond-int-type-OK.asn1.-P
index 431e42ce..5055e4d7 100644
--- a/tests/90-cond-int-type-OK.asn1.-P
+++ b/tests/90-cond-int-type-OK.asn1.-P
@@ -1754,7 +1754,7 @@ OK_IntegerInRange3_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
value = *(const long *)sptr;
- if((value >= -2147483648 && value <= 2147483647)) {
+ if((value >= (-2147483647L - 1) && value <= 2147483647)) {
/* Constraint check succeeded */
return 0;
} else {
@@ -1895,7 +1895,7 @@ OK_IntegerInRange4_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
value = *(const long *)sptr;
- if(((value == -2147483648) || (value == 2147483647))) {
+ if(((value == (-2147483647L - 1)) || (value == 2147483647))) {
/* Constraint check succeeded */
return 0;
} else {
@@ -2042,7 +2042,7 @@ OK_IntegerInRange5_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
return -1;
}
- if(((value == -2147483648) || (value == 2147483647))) {
+ if(((value == (-2147483647L - 1)) || (value == 2147483647))) {
/* Constraint check succeeded */
return 0;
} else {
diff --git a/tests/90-cond-int-type-OK.asn1.-Pfnative-types b/tests/90-cond-int-type-OK.asn1.-Pfnative-types
index 344c89a0..461e5eb5 100644
--- a/tests/90-cond-int-type-OK.asn1.-Pfnative-types
+++ b/tests/90-cond-int-type-OK.asn1.-Pfnative-types
@@ -1741,7 +1741,7 @@ OK_IntegerInRange3_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
value = *(const long *)sptr;
- if((value >= -2147483648 && value <= 2147483647)) {
+ if((value >= (-2147483647L - 1) && value <= 2147483647)) {
/* Constraint check succeeded */
return 0;
} else {
@@ -1882,7 +1882,7 @@ OK_IntegerInRange4_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
value = *(const long *)sptr;
- if(((value == -2147483648) || (value == 2147483647))) {
+ if(((value == (-2147483647L - 1)) || (value == 2147483647))) {
/* Constraint check succeeded */
return 0;
} else {
@@ -2023,7 +2023,7 @@ OK_IntegerInRange5_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
value = *(const long *)sptr;
- if(((value == -2147483648) || (value == 2147483647))) {
+ if(((value == (-2147483647L - 1)) || (value == 2147483647))) {
/* Constraint check succeeded */
return 0;
} else {
diff --git a/tests/90-cond-int-type-OK.asn1.-Pgen-PER b/tests/90-cond-int-type-OK.asn1.-Pgen-PER
index c7e90db2..d7957cba 100644
--- a/tests/90-cond-int-type-OK.asn1.-Pgen-PER
+++ b/tests/90-cond-int-type-OK.asn1.-Pgen-PER
@@ -2060,7 +2060,7 @@ OK_IntegerInRange3_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
value = *(const long *)sptr;
- if((value >= -2147483648 && value <= 2147483647)) {
+ if((value >= (-2147483647L - 1) && value <= 2147483647)) {
/* Constraint check succeeded */
return 0;
} else {
@@ -2155,7 +2155,7 @@ OK_IntegerInRange3_encode_uper(asn_TYPE_descriptor_t *td,
/*** <<< CTDEFS [OK-IntegerInRange3] >>> ***/
static asn_per_constraints_t asn_PER_type_OK_IntegerInRange3_constr_1 = {
- { APC_CONSTRAINED, 32, -1, -2147483648, 2147483647 } /* (-2147483648..2147483647) */,
+ { APC_CONSTRAINED, 32, -1, (-2147483647L - 1), 2147483647 } /* (-2147483648..2147483647) */,
{ APC_UNCONSTRAINED, -1, -1, 0, 0 },
0, 0 /* No PER value map */
};
@@ -2227,7 +2227,7 @@ OK_IntegerInRange4_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
value = *(const long *)sptr;
- if(((value == -2147483648) || (value == 2147483647))) {
+ if(((value == (-2147483647L - 1)) || (value == 2147483647))) {
/* Constraint check succeeded */
return 0;
} else {
@@ -2322,7 +2322,7 @@ OK_IntegerInRange4_encode_uper(asn_TYPE_descriptor_t *td,
/*** <<< CTDEFS [OK-IntegerInRange4] >>> ***/
static asn_per_constraints_t asn_PER_type_OK_IntegerInRange4_constr_1 = {
- { APC_CONSTRAINED, 32, -1, -2147483648, 2147483647 } /* (-2147483648..2147483647) */,
+ { APC_CONSTRAINED, 32, -1, (-2147483647L - 1), 2147483647 } /* (-2147483648..2147483647) */,
{ APC_UNCONSTRAINED, -1, -1, 0, 0 },
0, 0 /* No PER value map */
};
@@ -2400,7 +2400,7 @@ OK_IntegerInRange5_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
return -1;
}
- if(((value == -2147483648) || (value == 2147483647))) {
+ if(((value == (-2147483647L - 1)) || (value == 2147483647))) {
/* Constraint check succeeded */
return 0;
} else {
@@ -2495,7 +2495,7 @@ OK_IntegerInRange5_encode_uper(asn_TYPE_descriptor_t *td,
/*** <<< CTDEFS [OK-IntegerInRange5] >>> ***/
static asn_per_constraints_t asn_PER_type_OK_IntegerInRange5_constr_1 = {
- { APC_CONSTRAINED | APC_EXTENSIBLE, 32, -1, -2147483648, 2147483647 } /* (-2147483648..2147483647,...) */,
+ { APC_CONSTRAINED | APC_EXTENSIBLE, 32, -1, (-2147483647L - 1), 2147483647 } /* (-2147483648..2147483647,...) */,
{ APC_UNCONSTRAINED, -1, -1, 0, 0 },
0, 0 /* No PER value map */
};