Coverage Report

Created: 2022-07-22 12:05

/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
452k
{
16
452k
        char *ep;
17
452k
        unsigned long long ull;
18
19
452k
        errno = 0;
20
452k
        ull = strtoull(str, &ep, base);
21
452k
        if (str == ep || *ep != '\0')
22
74
                return -1;
23
452k
        else if (ull == ULLONG_MAX && errno == ERANGE)
24
10
                return -1;
25
452k
        else if (ull > UINT64_MAX)
26
0
                return -1;
27
452k
        *out = (uint64_t)ull;
28
29
452k
        return 0;
30
452k
}