Commit 1550e5c9 authored by Lev Walkin's avatar Lev Walkin

change type width detection logic

parent 334d5cc7
......@@ -26,11 +26,23 @@ static unsigned long i2ul(const INTEGER_t *i) {
return l;
}
static long i2l(const INTEGER_t *i) {
long l;
int ret = asn_INTEGER2long(i, &l);
assert(ret == 0);
return l;
}
static void ul2i(INTEGER_t *i, unsigned long l) {
int ret = asn_ulong2INTEGER(i, l);
assert(ret == 0);
}
static void l2i(INTEGER_t *i, long l) {
int ret = asn_long2INTEGER(i, l);
assert(ret == 0);
}
static void
verify(int testNo, T_t *ti) {
asn_enc_rval_t er;
......@@ -40,7 +52,7 @@ verify(int testNo, T_t *ti) {
fprintf(stderr, "%d IN: { %lu, %lu, %ld, %ld }\n", testNo,
i2ul(&ti->unsigned33), i2ul(&ti->unsigned42),
i2ul(&ti->signed33), ti->signed33ext
i2l(&ti->signed33), i2l(&ti->signed33ext)
);
er = uper_encode_to_buffer(&asn_DEF_T, ti, buf, sizeof buf);
......@@ -55,13 +67,13 @@ verify(int testNo, T_t *ti) {
fprintf(stderr, "%d OUT: { %lu, %lu, %ld, %ld } vs { %lu, %lu, %ld, %ld }\n",
testNo,
i2ul(&ti->unsigned33), i2ul(&ti->unsigned42),
i2ul(&ti->signed33), ti->signed33ext,
i2l(&ti->signed33), i2l(&ti->signed33ext),
i2ul(&to->unsigned33), i2ul(&to->unsigned42),
i2ul(&to->signed33), to->signed33ext);
i2l(&to->signed33), i2l(&to->signed33ext));
assert(i2ul(&ti->unsigned33) == i2ul(&to->unsigned33));
assert(i2ul(&ti->unsigned42) == i2ul(&to->unsigned42));
assert(i2ul(&ti->signed33) == i2ul(&to->signed33));
assert(ti->signed33ext == to->signed33ext);
assert(i2l(&ti->signed33) == i2l(&to->signed33));
assert(i2l(&ti->signed33ext) == i2l(&to->signed33ext));
xer_fprint(stderr, &asn_DEF_T, ti);
xer_fprint(stderr, &asn_DEF_T, to);
......@@ -72,8 +84,10 @@ NO_encode(int testNo, T_t *ti) {
asn_enc_rval_t er;
unsigned char buf[16];
fprintf(stderr, "%d IN: { %lu, %lu }\n", testNo,
i2ul(&ti->unsigned33), i2ul(&ti->unsigned42));
fprintf(stderr, "%d IN: { %lu, %lu, %ld, %ld }\n", testNo,
i2ul(&ti->unsigned33), i2ul(&ti->unsigned42),
i2l(&ti->signed33), i2l(&ti->signed33ext)
);
er = uper_encode_to_buffer(&asn_DEF_T, ti, buf, sizeof buf);
assert(er.encoded == -1);
......@@ -85,68 +99,69 @@ int main() {
memset(&ti, 0, sizeof(ti));
ul2i(&ti.unsigned33, 0);
ul2i(&ti.unsigned42, 0);
ul2i(&ti.signed33, 0);
ti.signed33ext = 0;
l2i(&ti.signed33, 0);
l2i(&ti.signed33ext, 0);
verify(1, &ti);
ul2i(&ti.unsigned33, 1);
ul2i(&ti.unsigned42, 1);
ul2i(&ti.signed33, 1);
ti.signed33ext = 1;
l2i(&ti.signed33, 1);
l2i(&ti.signed33ext, 1);
verify(2, &ti);
ul2i(&ti.unsigned33, 5000000000);
ul2i(&ti.unsigned42, 3153600000000);
ul2i(&ti.signed33, 4000000000);
ti.signed33ext = 4000000000;
l2i(&ti.signed33, 4000000000);
l2i(&ti.signed33ext, 4000000000);
verify(3, &ti);
ul2i(&ti.unsigned33, -1);
ul2i(&ti.unsigned42, 0);
ul2i(&ti.signed33, 0);
ti.signed33ext = 0;
l2i(&ti.signed33, 0);
l2i(&ti.signed33ext, 0);
NO_encode(4, &ti);
ul2i(&ti.unsigned33, 0);
ul2i(&ti.unsigned42, -1);
ul2i(&ti.signed33, 0);
ti.signed33ext = 0;
l2i(&ti.signed33, 0);
l2i(&ti.signed33ext, 0);
NO_encode(5, &ti);
ul2i(&ti.unsigned33, 0);
ul2i(&ti.unsigned42, 0);
ul2i(&ti.signed33, -4000000000-1);
ti.signed33ext = 0;
l2i(&ti.signed33, -4000000000-1);
l2i(&ti.signed33ext, 0);
NO_encode(6, &ti);
ul2i(&ti.unsigned33, 0);
ul2i(&ti.unsigned42, 0);
ul2i(&ti.signed33, 0);
ti.signed33ext = -4000000000-1;
l2i(&ti.signed33, 0);
l2i(&ti.signed33ext, -4000000000-1);
assert(ti.signed33ext.size == 5);
verify(7, &ti); /* signed33ext is extensible */
ul2i(&ti.unsigned33, 5000000000 + 1);
ul2i(&ti.unsigned42, 0);
ul2i(&ti.signed33, 0);
ti.signed33ext = 0;
l2i(&ti.signed33, 0);
l2i(&ti.signed33ext, 0);
NO_encode(8, &ti);
ul2i(&ti.unsigned33, 0);
ul2i(&ti.unsigned42, 3153600000000 + 1);
ul2i(&ti.signed33, 0);
ti.signed33ext = 0;
l2i(&ti.signed33, 0);
l2i(&ti.signed33ext, 0);
NO_encode(9, &ti);
ul2i(&ti.unsigned33, 5000000000 - 1);
ul2i(&ti.unsigned42, 3153600000000 - 1);
ul2i(&ti.signed33, 4000000000 - 1);
ti.signed33ext = 4000000000 - 1;
l2i(&ti.signed33, 4000000000 - 1);
l2i(&ti.signed33ext, 4000000000 - 1);
verify(10, &ti);
ul2i(&ti.unsigned33, 0);
ul2i(&ti.unsigned42, 0);
ul2i(&ti.signed33, 0);
ti.signed33ext = 4000000000 + 1;
l2i(&ti.signed33, 0);
l2i(&ti.signed33ext, 4000000000 + 1);
verify(11, &ti);
return 0;
......
......@@ -2,7 +2,6 @@
/*** <<< INCLUDES [T] >>> ***/
#include <INTEGER.h>
#include <NativeInteger.h>
#include <constr_SEQUENCE.h>
/*** <<< TYPE-DECLS [T] >>> ***/
......@@ -11,7 +10,7 @@ typedef struct T {
INTEGER_t unsigned33;
INTEGER_t unsigned42;
INTEGER_t signed33;
long signed33ext;
INTEGER_t signed33ext;
/* Context for parsing across buffer boundaries */
asn_struct_ctx_t _asn_ctx;
......@@ -119,6 +118,7 @@ memb_signed33_constraint_1(asn_TYPE_descriptor_t *td, const void *sptr,
static int
memb_signed33ext_constraint_1(asn_TYPE_descriptor_t *td, const void *sptr,
asn_app_constraint_failed_f *ctfailcb, void *app_key) {
const INTEGER_t *st = (const INTEGER_t *)sptr;
long value;
if(!sptr) {
......@@ -128,7 +128,12 @@ memb_signed33ext_constraint_1(asn_TYPE_descriptor_t *td, const void *sptr,
return -1;
}
value = *(const long *)sptr;
if(asn_INTEGER2long(st, &value)) {
_ASN_CTFAIL(app_key, td, sptr,
"%s: value too large (%s:%d)",
td->name, __FILE__, __LINE__);
return -1;
}
if((value >= -4000000000 && value <= 4000000000)) {
/* Constraint check succeeded */
......@@ -198,7 +203,7 @@ static asn_TYPE_member_t asn_MBR_T_1[] = {
{ ATF_NOFLAGS, 0, offsetof(struct T, signed33ext),
.tag = (ASN_TAG_CLASS_CONTEXT | (3 << 2)),
.tag_mode = -1, /* IMPLICIT tag at current level */
.type = &asn_DEF_NativeInteger,
.type = &asn_DEF_INTEGER,
.memb_constraints = memb_signed33ext_constraint_1,
.per_constraints = &asn_PER_memb_signed33ext_constr_5,
.default_value = 0,
......
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