X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/46b0747592074017ff0ea4b33d4a7194235886e5..51998949e60e2a7e86e4393b315cfb76a58ca80d:/libs/smux/constr_SET_OF.c?ds=inline diff --git a/libs/smux/constr_SET_OF.c b/libs/smux/constr_SET_OF.c index 0d5efa4f..2dbc6e51 100644 --- a/libs/smux/constr_SET_OF.c +++ b/libs/smux/constr_SET_OF.c @@ -227,6 +227,8 @@ SET_OF_decode_ber(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, } /* Fall through */ case RC_FAIL: /* Fatal error */ + ASN_STRUCT_FREE(*elm->type, ctx->ptr); + ctx->ptr = 0; RETURN(RC_FAIL); } /* switch(rval) */ @@ -357,7 +359,7 @@ SET_OF_encode_der(asn_TYPE_descriptor_t *td, void *ptr, if(!cb || list->count == 0) { erval.encoded = computed_size; - _ASN_ENCODED_OK(erval); + ASN__ENCODED_OK(erval); } /* @@ -449,7 +451,7 @@ SET_OF_encode_der(asn_TYPE_descriptor_t *td, void *ptr, erval.encoded = computed_size; } - _ASN_ENCODED_OK(erval); + ASN__ENCODED_OK(erval); } #undef XER_ADVANCE @@ -547,11 +549,12 @@ SET_OF_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, */ ch_size = xer_next_token(&ctx->context, buf_ptr, size, &ch_type); - switch(ch_size) { - case -1: RETURN(RC_FAIL); - case 0: RETURN(RC_WMORE); - default: + if(ch_size == -1) { + RETURN(RC_FAIL); + } else { switch(ch_type) { + case PXER_WMORE: + RETURN(RC_WMORE); case PXER_COMMENT: /* Got XML comment */ case PXER_TEXT: /* Ignore free-standing text */ XER_ADVANCE(ch_size); /* Skip silently */ @@ -665,11 +668,11 @@ SET_OF_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, asn_app_consume_bytes_f *original_cb = cb; int i; - if(!sptr) _ASN_ENCODE_FAILED; + if(!sptr) ASN__ENCODE_FAILED; if(xcan) { encs = (xer_tmp_enc_t *)MALLOC(list->count * sizeof(encs[0])); - if(!encs) _ASN_ENCODE_FAILED; + if(!encs) ASN__ENCODE_FAILED; cb = SET_OF_encode_xer_callback; } @@ -688,12 +691,12 @@ SET_OF_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, } if(mname) { - if(!xcan) _i_ASN_TEXT_INDENT(1, ilevel); - _ASN_CALLBACK3("<", 1, mname, mlen, ">", 1); + if(!xcan) ASN__TEXT_INDENT(1, ilevel); + ASN__CALLBACK3("<", 1, mname, mlen, ">", 1); } if(!xcan && specs->as_XMLValueList == 1) - _i_ASN_TEXT_INDENT(1, ilevel + 1); + ASN__TEXT_INDENT(1, ilevel + 1); tmper = elm->type->xer_encoder(elm->type, memb_ptr, ilevel + (specs->as_XMLValueList != 2), flags, cb, app_key); @@ -705,18 +708,18 @@ SET_OF_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, if(tmper.encoded == 0 && specs->as_XMLValueList) { const char *name = elm->type->xml_tag; size_t len = strlen(name); - _ASN_CALLBACK3("<", 1, name, len, "/>", 2); + ASN__CALLBACK3("<", 1, name, len, "/>", 2); } if(mname) { - _ASN_CALLBACK3("", 1); + ASN__CALLBACK3("", 1); er.encoded += 5; } er.encoded += (2 * mlen) + tmper.encoded; } - if(!xcan) _i_ASN_TEXT_INDENT(1, ilevel - 1); + if(!xcan) ASN__TEXT_INDENT(1, ilevel - 1); if(encs) { xer_tmp_enc_t *enc = encs; @@ -728,7 +731,7 @@ SET_OF_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, qsort(encs, encs_count, sizeof(encs[0]), SET_OF_xer_order); for(; enc < end; enc++) { - _ASN_CALLBACK(enc->buffer, enc->offset); + ASN__CALLBACK(enc->buffer, enc->offset); FREEMEM(enc->buffer); enc->buffer = 0; control_size += enc->offset; @@ -749,7 +752,7 @@ cleanup: } FREEMEM(encs); } - _ASN_ENCODED_OK(er); + ASN__ENCODED_OK(er); } int @@ -787,8 +790,10 @@ SET_OF_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, void SET_OF_free(asn_TYPE_descriptor_t *td, void *ptr, int contents_only) { if(td && ptr) { + asn_SET_OF_specifics_t *specs; asn_TYPE_member_t *elm = td->elements; asn_anonymous_set_ *list = _A_SET_FROM_VOID(ptr); + asn_struct_ctx_t *ctx; /* Decoder context */ int i; /* @@ -804,6 +809,13 @@ SET_OF_free(asn_TYPE_descriptor_t *td, void *ptr, int contents_only) { asn_set_empty(list); /* Remove (list->array) */ + specs = (asn_SET_OF_specifics_t *)td->specifics; + ctx = (asn_struct_ctx_t *)((char *)ptr + specs->ctx_offset); + if(ctx->ptr) { + ASN_STRUCT_FREE(*elm->type, ctx->ptr); + ctx->ptr = 0; + } + if(!contents_only) { FREEMEM(ptr); } @@ -819,7 +831,7 @@ SET_OF_constraint(asn_TYPE_descriptor_t *td, const void *sptr, int i; if(!sptr) { - _ASN_CTFAIL(app_key, td, + ASN__CTFAIL(app_key, td, sptr, "%s: value not given (%s:%d)", td->name, __FILE__, __LINE__); return -1; @@ -864,15 +876,15 @@ SET_OF_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, int repeat = 0; ssize_t nelems; - if(_ASN_STACK_OVERFLOW_CHECK(opt_codec_ctx)) - _ASN_DECODE_FAILED; + if(ASN__STACK_OVERFLOW_CHECK(opt_codec_ctx)) + ASN__DECODE_FAILED; /* * Create the target structure if it is not present already. */ if(!st) { st = *sptr = CALLOC(1, specs->struct_size); - if(!st) _ASN_DECODE_FAILED; + if(!st) ASN__DECODE_FAILED; } list = _A_SET_FROM_VOID(st); @@ -883,7 +895,7 @@ SET_OF_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, if(ct && ct->flags & APC_EXTENSIBLE) { int value = per_get_few_bits(pd, 1); - if(value < 0) _ASN_DECODE_STARVED; + if(value < 0) ASN__DECODE_STARVED; if(value) ct = 0; /* Not restricted! */ } @@ -892,7 +904,7 @@ SET_OF_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, nelems = per_get_few_bits(pd, ct->effective_bits); ASN_DEBUG("Preparing to fetch %ld+%ld elements from %s", (long)nelems, ct->lower_bound, td->name); - if(nelems < 0) _ASN_DECODE_STARVED; + if(nelems < 0) ASN__DECODE_STARVED; nelems += ct->lower_bound; } else { nelems = -1; @@ -904,8 +916,8 @@ SET_OF_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, nelems = uper_get_length(pd, ct ? ct->effective_bits : -1, &repeat); ASN_DEBUG("Got to decode %d elements (eff %d)", - (int)nelems, ct ? ct->effective_bits : -1); - if(nelems < 0) _ASN_DECODE_STARVED; + (int)nelems, (int)(ct ? ct->effective_bits : -1)); + if(nelems < 0) ASN__DECODE_STARVED; } for(i = 0; i < nelems; i++) {