2 * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>.
4 * Redistribution and modifications are permitted subject to BSD license.
6 #include <asn_internal.h>
7 #include <constr_SEQUENCE.h>
9 asn_random_fill_result_t
10 SEQUENCE_random_fill(const asn_TYPE_descriptor_t *td, void **sptr,
11 const asn_encoding_constraints_t *constr,
13 const asn_SEQUENCE_specifics_t *specs =
14 (const asn_SEQUENCE_specifics_t *)td->specifics;
15 asn_random_fill_result_t result_ok = {ARFILL_OK, 0};
16 asn_random_fill_result_t result_failed = {ARFILL_FAILED, 0};
17 asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0};
21 if(max_length == 0) return result_skipped;
26 st = CALLOC(1, specs->struct_size);
32 for(edx = 0; edx < td->elements_count; edx++) {
33 const asn_TYPE_member_t *elm = &td->elements[edx];
34 void *memb_ptr; /* Pointer to the member */
35 void **memb_ptr2; /* Pointer to that pointer */
36 asn_random_fill_result_t tmpres;
38 if(elm->optional && asn_random_between(0, 4) == 2) {
39 /* Sometimes decide not to fill the optional value */
43 if(elm->flags & ATF_POINTER) {
44 /* Member is a pointer to another structure */
45 memb_ptr2 = (void **)((char *)st + elm->memb_offset);
47 memb_ptr = (char *)st + elm->memb_offset;
48 memb_ptr2 = &memb_ptr;
51 tmpres = elm->type->op->random_fill(
52 elm->type, memb_ptr2, &elm->encoding_constraints,
53 max_length > result_ok.length ? max_length - result_ok.length : 0);
56 result_ok.length += tmpres.length;
59 assert(!(elm->flags & ATF_POINTER) || *memb_ptr2 == NULL);
63 ASN_STRUCT_RESET(*td, st);
65 ASN_STRUCT_FREE(*td, st);