Coverage Report

Created: 2022-04-27 14:33

/libfido2/src/util.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 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
 */
6
7
#include <errno.h>
8
#include <stdint.h>
9
#include <stdlib.h>
10
11
#include "fido.h"
12
13
int
14
fido_to_uint64(const char *str, int base, uint64_t *out)
15
555k
{
16
555k
        char *ep;
17
555k
        unsigned long long ull;
18
19
555k
        errno = 0;
20
555k
        ull = strtoull(str, &ep, base);
21
555k
        if (str == ep || *ep != '\0')
22
72
                return -1;
23
555k
        else if (ull == ULLONG_MAX && errno == ERANGE)
24
10
                return -1;
25
555k
        else if (ull > UINT64_MAX)
26
0
                return -1;
27
555k
        *out = (uint64_t)ull;
28
29
555k
        return 0;
30
555k
}