Coverage Report

Created: 2026-06-30 06:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/open5gs/lib/asn1c/common/constr_CHOICE_rfill.c
Line
Count
Source
1
/*
2
 * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>.
3
 * All rights reserved.
4
 * Redistribution and modifications are permitted subject to BSD license.
5
 */
6
#include <asn_internal.h>
7
#include <constr_CHOICE.h>
8
9
asn_random_fill_result_t
10
CHOICE_random_fill(const asn_TYPE_descriptor_t *td, void **sptr,
11
                   const asn_encoding_constraints_t *constr,
12
0
                   size_t max_length) {
13
0
    const asn_CHOICE_specifics_t *specs =
14
0
        (const asn_CHOICE_specifics_t *)td->specifics;
15
0
    asn_random_fill_result_t res;
16
0
    asn_random_fill_result_t result_failed = {ARFILL_FAILED, 0};
17
0
    asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0};
18
0
    const asn_TYPE_member_t *elm;
19
0
    unsigned present;
20
0
    void *memb_ptr;    /* Pointer to the member */
21
0
    void **memb_ptr2;  /* Pointer to that pointer */
22
0
    void *st = *sptr;
23
24
0
    if(max_length == 0) return result_skipped;
25
26
0
    (void)constr;
27
28
0
    if(st == NULL) {
29
0
        st = CALLOC(1, specs->struct_size);
30
0
        if(st == NULL) {
31
0
            return result_failed;
32
0
        }
33
0
    }
34
35
0
    present = asn_random_between(1, td->elements_count);
36
0
    elm = &td->elements[present - 1];
37
38
0
    if(elm->flags & ATF_POINTER) {
39
        /* Member is a pointer to another structure */
40
0
        memb_ptr2 = (void **)((char *)st + elm->memb_offset);
41
0
    } else {
42
0
        memb_ptr = (char *)st + elm->memb_offset;
43
0
        memb_ptr2 = &memb_ptr;
44
0
    }
45
46
0
    res = elm->type->op->random_fill(elm->type, memb_ptr2,
47
0
                                    &elm->encoding_constraints, max_length);
48
0
    _set_present_idx(st, specs->pres_offset, specs->pres_size, present);
49
0
    if(res.code == ARFILL_OK) {
50
0
        *sptr = st;
51
0
    } else {
52
0
        if(st == *sptr) {
53
0
            ASN_STRUCT_RESET(*td, st);
54
0
        } else {
55
0
            ASN_STRUCT_FREE(*td, st);
56
0
        }
57
0
    }
58
59
0
    return res;
60
0
}