## Coverage Report

#### Created: 2023-09-23 17:42

    /libfido2/src/types.c

    Line
    Count
    Source
    1
    /*
    2
     * Copyright (c) 2018-2022 Yubico AB. All rights reserved.
    3
     * Use of this source code is governed by a BSD-style
    4
     * license that can be found in the LICENSE file.
    5
     * SPDX-License-Identifier: BSD-2-Clause
    6
     */
    7
    8
    #include "fido.h"
    9
    10
    void
    11
    fido_str_array_free(fido_str_array_t *sa)
    12
    178k
    {
    13
    245k
            for (size_t i = 0; i < sa->len; i++)
    14
    67.6k
                    free(sa->ptr[i]);
    15
    16
    178k
            free(sa->ptr);
    17
    178k
            sa->ptr = NULL;
    18
    178k
            sa->len = 0;
    19
    178k
    }
    20
    21
    void
    22
    fido_opt_array_free(fido_opt_array_t *oa)
    23
    59.1k
    {
    24
    94.3k
            for (size_t i = 0; i < oa->len; i++)
    25
    35.2k
                    free(oa->name[i]);
    26
    27
    59.1k
            free(oa->name);
    28
    59.1k
            free(oa->value);
    29
    59.1k
            oa->name = NULL;
    30
    59.1k
            oa->value = NULL;
    31
    59.1k
            oa->len = 0;
    32
    59.1k
    }
    33
    34
    void
    35
    fido_byte_array_free(fido_byte_array_t *ba)
    36
    59.1k
    {
    37
    59.1k
            free(ba->ptr);
    38
    39
    59.1k
            ba->ptr = NULL;
    40
    59.1k
            ba->len = 0;
    41
    59.1k
    }
    42
    43
    void
    44
    fido_algo_free(fido_algo_t *a)
    45
    10.4k
    {
    46
    10.4k
            free(a->type);
    47
    10.4k
            a->type = NULL;
    48
    10.4k
            a->cose = 0;
    49
    10.4k
    }
    50
    51
    void
    52
    fido_algo_array_free(fido_algo_array_t *aa)
    53
    59.1k
    {
    54
    68.9k
            for (size_t i = 0; i < aa->len; i++)
    55
    9.84k
                    fido_algo_free(&aa->ptr[i]);
    56
    57
    59.1k
            free(aa->ptr);
    58
    59.1k
            aa->ptr = NULL;
    59
    59.1k
            aa->len = 0;
    60
    59.1k
    }
    61
    62
    void
    63
    fido_cert_array_free(fido_cert_array_t *ca)
    64
    59.1k
    {
    65
    59.8k
            for (size_t i = 0; i < ca->len; i++)
    66
    715
                    free(ca->name[i]);
    67
    68
    59.1k
            free(ca->name);
    69
    59.1k
            free(ca->value);
    70
    59.1k
            ca->name = NULL;
    71
    59.1k
            ca->value = NULL;
    72
    59.1k
            ca->len = 0;
    73
    59.1k
    }
    74
    75
    int
    76
    fido_str_array_pack(fido_str_array_t *sa, const char * const *v, size_t n)
    77
    953
    {
    78
    953
            if ((sa->ptr = calloc(n, sizeof(char *))) == NULL) {
    79
    4
                    fido_log_debug("%s: calloc", __func__);
    80
    4
                    return -1;
    81
    4
            }
    82
    29.6k
            for (size_t i = 0; i < n; i++) {
    83
    28.8k
                    if ((sa->ptr[i] = strdup(v[i])) == NULL) {
    84
    54
                            fido_log_debug("%s: strdup", __func__);
    85
    54
                            return -1;
    86
    54
                    }
    87
    28.7k
                    sa->len++;
    88
    28.7k
            }
    89
    90
    895
            return 0;
    91
    949
    }