Commit 8282f80b authored by Raphael Riebl's avatar Raphael Riebl Committed by Mouse

INTEGER_uper: tidy up use of (u)intmax_t at encoding

parent fe2c1f69
......@@ -134,7 +134,10 @@ INTEGER_encode_uper(const asn_TYPE_descriptor_t *td,
const uint8_t *buf;
const uint8_t *end;
const asn_per_constraint_t *ct;
intmax_t value = 0;
union {
intmax_t s;
uintmax_t u;
} value;
if(!st || st->size == 0) ASN__ENCODE_FAILED;
......@@ -146,37 +149,35 @@ INTEGER_encode_uper(const asn_TYPE_descriptor_t *td,
if(ct) {
int inext = 0;
if(specs && specs->field_unsigned) {
uintmax_t uval;
if(asn_INTEGER2umax(st, &uval))
if(asn_INTEGER2umax(st, &value.u))
ASN__ENCODE_FAILED;
/* Check proper range */
if(ct->flags & APC_SEMI_CONSTRAINED) {
if(uval < (uintmax_t)ct->lower_bound)
if(value.u < (uintmax_t)ct->lower_bound)
inext = 1;
} else if(ct->range_bits >= 0) {
if(uval < (uintmax_t)ct->lower_bound
|| uval > (uintmax_t)ct->upper_bound)
if(value.u < (uintmax_t)ct->lower_bound
|| value.u > (uintmax_t)ct->upper_bound)
inext = 1;
}
ASN_DEBUG("Value %lu (%02x/%" ASN_PRI_SIZE ") lb %lu ub %lu %s",
uval, st->buf[0], st->size,
value.u, st->buf[0], st->size,
ct->lower_bound, ct->upper_bound,
inext ? "ext" : "fix");
value = uval;
} else {
if(asn_INTEGER2imax(st, &value))
if(asn_INTEGER2imax(st, &value.s))
ASN__ENCODE_FAILED;
/* Check proper range */
if(ct->flags & APC_SEMI_CONSTRAINED) {
if(value < ct->lower_bound)
if(value.s < ct->lower_bound)
inext = 1;
} else if(ct->range_bits >= 0) {
if(value < ct->lower_bound
|| value > ct->upper_bound)
if(value.s < ct->lower_bound
|| value.s > ct->upper_bound)
inext = 1;
}
ASN_DEBUG("Value %ld (%02x/%" ASN_PRI_SIZE ") lb %ld ub %ld %s",
value, st->buf[0], st->size,
value.s, st->buf[0], st->size,
ct->lower_bound, ct->upper_bound,
inext ? "ext" : "fix");
}
......@@ -193,22 +194,22 @@ INTEGER_encode_uper(const asn_TYPE_descriptor_t *td,
if(ct && ct->range_bits >= 0) {
uintmax_t v;
/* #11.5.6 -> #11.3 */
ASN_DEBUG("Encoding integer %ld (%lu) with range %d bits",
value, value - ct->lower_bound, ct->range_bits);
if(specs && specs->field_unsigned) {
if(((uintmax_t)ct->lower_bound > (uintmax_t)(ct->upper_bound)
|| ((uintmax_t)value < (uintmax_t)ct->lower_bound))
|| ((uintmax_t)value > (uintmax_t)ct->upper_bound)) {
|| (value.u < (uintmax_t)ct->lower_bound))
|| (value.u > (uintmax_t)ct->upper_bound)) {
ASN_DEBUG("Value %lu to-be-encoded is outside the bounds [%lu, %lu]!",
value, ct->lower_bound, ct->upper_bound);
value.u, ct->lower_bound, ct->upper_bound);
ASN__ENCODE_FAILED;
}
v = (uintmax_t)value - (uintmax_t)ct->lower_bound;
v = value.u - (uintmax_t)ct->lower_bound;
} else {
if(per_imax_range_rebase(value, ct->lower_bound, ct->upper_bound, &v)) {
if(per_imax_range_rebase(value.s, ct->lower_bound, ct->upper_bound, &v)) {
ASN__ENCODE_FAILED;
}
}
ASN_DEBUG("Encoding integer %lu with range %d bits",
v, ct->range_bits);
if(uper_put_constrained_whole_number_u(po, v, ct->range_bits))
ASN__ENCODE_FAILED;
ASN__ENCODED_OK(er);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment