From 63a35237b1704f1491f6a8c40dca6a02b3781e96 Mon Sep 17 00:00:00 2001 From: Lev Walkin Date: Thu, 10 Aug 2017 19:59:47 -0700 Subject: [PATCH] presence unsigned --- skeletons/constr_CHOICE.c | 47 +++++++++++++++++++-------------------- skeletons/constr_CHOICE.h | 32 +++++++++++++------------- 2 files changed, 39 insertions(+), 40 deletions(-) diff --git a/skeletons/constr_CHOICE.c b/skeletons/constr_CHOICE.c index e7adbf75..435d592f 100644 --- a/skeletons/constr_CHOICE.c +++ b/skeletons/constr_CHOICE.c @@ -67,7 +67,7 @@ static signed _fetch_present_idx(const void *struct_ptr, int off, int size); static void _set_present_idx(void *sptr, int offset, int size, int pres); static const void *_get_member_ptr(const asn_TYPE_descriptor_t *, const void *sptr, asn_TYPE_member_t **elm, - signed *present); + unsigned *present); /* * Tags are canonically sorted in the tag to member table. @@ -365,7 +365,7 @@ CHOICE_encode_der(asn_TYPE_descriptor_t *td, void *sptr, asn_enc_rval_t erval; void *memb_ptr; size_t computed_size = 0; - signed present; + unsigned present; if(!sptr) ASN__ENCODE_FAILED; @@ -379,7 +379,7 @@ CHOICE_encode_der(asn_TYPE_descriptor_t *td, void *sptr, * If the structure was not initialized, it cannot be encoded: * can't deduce what to encode in the choice type. */ - if(present <= 0 || (unsigned)present > td->elements_count) { + if(present == 0 || present > td->elements_count) { if(present == 0 && td->elements_count == 0) { /* The CHOICE is empty?! */ erval.encoded = 0; @@ -450,7 +450,7 @@ CHOICE_encode_der(asn_TYPE_descriptor_t *td, void *sptr, ber_tlv_tag_t CHOICE_outmost_tag(const asn_TYPE_descriptor_t *td, const void *ptr, int tag_mode, ber_tlv_tag_t tag) { asn_CHOICE_specifics_t *specs = (asn_CHOICE_specifics_t *)td->specifics; - signed present; + unsigned present; assert(tag_mode == 0); (void)tag_mode; assert(tag == 0); (void)tag; @@ -460,7 +460,7 @@ CHOICE_outmost_tag(const asn_TYPE_descriptor_t *td, const void *ptr, int tag_mod */ present = _fetch_present_idx(ptr, specs->pres_offset, specs->pres_size); - if(present > 0 && (unsigned)present <= td->elements_count) { + if(present > 0 && present <= td->elements_count) { const asn_TYPE_member_t *elm = &td->elements[present-1]; const void *memb_ptr; @@ -483,7 +483,7 @@ int CHOICE_constraint(asn_TYPE_descriptor_t *td, const void *sptr, asn_app_constraint_failed_f *ctfailcb, void *app_key) { asn_CHOICE_specifics_t *specs = (asn_CHOICE_specifics_t *)td->specifics; - signed present; + unsigned present; if(!sptr) { ASN__CTFAIL(app_key, td, sptr, @@ -496,7 +496,7 @@ CHOICE_constraint(asn_TYPE_descriptor_t *td, const void *sptr, * Figure out which CHOICE element is encoded. */ present = _fetch_present_idx(sptr, specs->pres_offset,specs->pres_size); - if(present > 0 && (unsigned)present <= td->elements_count) { + if(present > 0 && present <= td->elements_count) { asn_TYPE_member_t *elm = &td->elements[present-1]; const void *memb_ptr; @@ -780,7 +780,7 @@ CHOICE_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, asn_app_consume_bytes_f *cb, void *app_key) { asn_CHOICE_specifics_t *specs=(asn_CHOICE_specifics_t *)td->specifics; asn_enc_rval_t er; - signed present; + unsigned present; if(!sptr) ASN__ENCODE_FAILED; @@ -790,7 +790,7 @@ CHOICE_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, */ present = _fetch_present_idx(sptr, specs->pres_offset,specs->pres_size); - if(present <= 0 || (unsigned)present > td->elements_count) { + if(present == 0 || present > td->elements_count) { ASN__ENCODE_FAILED; } else { asn_enc_rval_t tmper; @@ -917,7 +917,7 @@ CHOICE_encode_uper(asn_TYPE_descriptor_t *td, asn_TYPE_member_t *elm; /* CHOICE's element */ const asn_per_constraint_t *ct; void *memb_ptr; - signed present; + unsigned present; int present_enc; if(!sptr) ASN__ENCODE_FAILED; @@ -928,14 +928,13 @@ CHOICE_encode_uper(asn_TYPE_descriptor_t *td, else if(td->per_constraints) ct = &td->per_constraints->value; else ct = 0; - present = _fetch_present_idx(sptr, - specs->pres_offset, specs->pres_size); + present = _fetch_present_idx(sptr, specs->pres_offset, specs->pres_size); - /* + /* * If the structure was not initialized properly, it cannot be encoded: * can't deduce what to encode in the choice type. */ - if(present <= 0 || (unsigned)present > td->elements_count) + if(present == 0 || present > td->elements_count) ASN__ENCODE_FAILED; else present--; @@ -998,7 +997,7 @@ int CHOICE_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, asn_app_consume_bytes_f *cb, void *app_key) { asn_CHOICE_specifics_t *specs = (asn_CHOICE_specifics_t *)td->specifics; - signed present; + unsigned present; if(!sptr) return (cb("", 8, app_key) < 0) ? -1 : 0; @@ -1010,7 +1009,7 @@ CHOICE_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, /* * Print that element. */ - if(present > 0 && (unsigned)present <= td->elements_count) { + if(present > 0 && present <= td->elements_count) { asn_TYPE_member_t *elm = &td->elements[present-1]; const void *memb_ptr; @@ -1038,7 +1037,7 @@ CHOICE_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, void CHOICE_free(asn_TYPE_descriptor_t *td, void *ptr, int contents_only) { asn_CHOICE_specifics_t *specs = (asn_CHOICE_specifics_t *)td->specifics; - signed present; + unsigned present; if(!td || !ptr) return; @@ -1053,7 +1052,7 @@ CHOICE_free(asn_TYPE_descriptor_t *td, void *ptr, int contents_only) { /* * Free that element. */ - if(present > 0 && (unsigned)present <= td->elements_count) { + if(present > 0 && present <= td->elements_count) { asn_TYPE_member_t *elm = &td->elements[present-1]; void *memb_ptr; @@ -1085,7 +1084,7 @@ CHOICE_free(asn_TYPE_descriptor_t *td, void *ptr, int contents_only) { static signed _fetch_present_idx(const void *struct_ptr, int pres_offset, int pres_size) { const void *present_ptr; - signed present; + unsigned present; present_ptr = ((const char *)struct_ptr) + pres_offset; @@ -1119,9 +1118,9 @@ _set_present_idx(void *struct_ptr, int pres_offset, int pres_size, int present) static const void * _get_member_ptr(const asn_TYPE_descriptor_t *td, const void *sptr, - asn_TYPE_member_t **elm_ptr, signed *present_out) { + asn_TYPE_member_t **elm_ptr, unsigned *present_out) { asn_CHOICE_specifics_t *specs = (asn_CHOICE_specifics_t *)td->specifics; - signed present; + unsigned present; if(!sptr) { *elm_ptr = NULL; @@ -1139,7 +1138,7 @@ _get_member_ptr(const asn_TYPE_descriptor_t *td, const void *sptr, * The presence index is intentionally 1-based to avoid * treating zeroed structure as a valid one. */ - if(present > 0 && (unsigned)present <= td->elements_count) { + if(present > 0 && present <= td->elements_count) { asn_TYPE_member_t *const elm = &td->elements[present - 1]; const void *memb_ptr; @@ -1162,8 +1161,8 @@ int CHOICE_compare(const asn_TYPE_descriptor_t *td, const void *aptr, const void *bptr) { asn_TYPE_member_t *aelm; asn_TYPE_member_t *belm; - signed apresent = 0; - signed bpresent = 0; + unsigned apresent = 0; + unsigned bpresent = 0; const void *amember = _get_member_ptr(td, aptr, &aelm, &apresent); const void *bmember = _get_member_ptr(td, bptr, &belm, &apresent); diff --git a/skeletons/constr_CHOICE.h b/skeletons/constr_CHOICE.h index c30c1816..3c3b6cae 100644 --- a/skeletons/constr_CHOICE.h +++ b/skeletons/constr_CHOICE.h @@ -13,27 +13,27 @@ extern "C" { #endif typedef const struct asn_CHOICE_specifics_s { - /* - * Target structure description. - */ - int struct_size; /* Size of the target structure. */ - int ctx_offset; /* Offset of the asn_codec_ctx_t member */ - int pres_offset; /* Identifier of the present member */ - int pres_size; /* Size of the identifier (enum) */ + /* + * Target structure description. + */ + unsigned struct_size; /* Size of the target structure. */ + unsigned ctx_offset; /* Offset of the asn_codec_ctx_t member */ + unsigned pres_offset; /* Identifier of the present member */ + unsigned pres_size; /* Size of the identifier (enum) */ - /* - * Tags to members mapping table. - */ - const asn_TYPE_tag2member_t *tag2el; + /* + * Tags to members mapping table. + */ + const asn_TYPE_tag2member_t *tag2el; unsigned tag2el_count; /* Canonical ordering of CHOICE elements, for PER */ - int *canonical_order; + const int *canonical_order; - /* - * Extensions-related stuff. - */ - signed ext_start; /* First member of extensions, or -1 */ + /* + * Extensions-related stuff. + */ + signed ext_start; /* First member of extensions, or -1 */ } asn_CHOICE_specifics_t; /*