Coverage Report

Created: 2025-11-11 06:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/uriparser/src/UriIp4Base.c
Line
Count
Source
1
/*
2
 * uriparser - RFC 3986 URI parsing library
3
 *
4
 * Copyright (C) 2007, Weijia Song <songweijia@gmail.com>
5
 * Copyright (C) 2007, Sebastian Pipping <sebastian@pipping.org>
6
 * All rights reserved.
7
 *
8
 * Redistribution and use in source  and binary forms, with or without
9
 * modification, are permitted provided  that the following conditions
10
 * are met:
11
 *
12
 *     1. Redistributions  of  source  code   must  retain  the  above
13
 *        copyright notice, this list  of conditions and the following
14
 *        disclaimer.
15
 *
16
 *     2. Redistributions  in binary  form  must  reproduce the  above
17
 *        copyright notice, this list  of conditions and the following
18
 *        disclaimer  in  the  documentation  and/or  other  materials
19
 *        provided with the distribution.
20
 *
21
 *     3. Neither the  name of the  copyright holder nor the  names of
22
 *        its contributors may be used  to endorse or promote products
23
 *        derived from  this software  without specific  prior written
24
 *        permission.
25
 *
26
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27
 * "AS IS" AND  ANY EXPRESS OR IMPLIED WARRANTIES,  INCLUDING, BUT NOT
28
 * LIMITED TO,  THE IMPLIED WARRANTIES OF  MERCHANTABILITY AND FITNESS
29
 * FOR  A  PARTICULAR  PURPOSE  ARE  DISCLAIMED.  IN  NO  EVENT  SHALL
30
 * THE  COPYRIGHT HOLDER  OR CONTRIBUTORS  BE LIABLE  FOR ANY  DIRECT,
31
 * INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL DAMAGES
32
 * (INCLUDING, BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS OR
33
 * SERVICES; LOSS OF USE, DATA,  OR PROFITS; OR BUSINESS INTERRUPTION)
34
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
35
 * STRICT  LIABILITY,  OR  TORT (INCLUDING  NEGLIGENCE  OR  OTHERWISE)
36
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
37
 * OF THE POSSIBILITY OF SUCH DAMAGE.
38
 */
39
40
/**
41
 * @file UriIp4Base.c
42
 * Holds code independent of the encoding pass.
43
 */
44
45
#ifndef URI_DOXYGEN
46
#  include "UriIp4Base.h"
47
#endif
48
49
1.90k
void uriStackToOctet(UriIp4Parser * parser, unsigned char * octet) {
50
1.90k
    switch (parser->stackCount) {
51
1.12k
    case 1:
52
1.12k
        *octet = parser->stackOne;
53
1.12k
        break;
54
55
594
    case 2:
56
594
        *octet = parser->stackOne * 10 + parser->stackTwo;
57
594
        break;
58
59
186
    case 3:
60
186
        *octet = parser->stackOne * 100 + parser->stackTwo * 10 + parser->stackThree;
61
186
        break;
62
63
0
    default:;
64
1.90k
    }
65
1.90k
    parser->stackCount = 0;
66
1.90k
}
67
68
7.33k
void uriPushToStack(UriIp4Parser * parser, unsigned char digit) {
69
7.33k
    switch (parser->stackCount) {
70
4.75k
    case 0:
71
4.75k
        parser->stackOne = digit;
72
4.75k
        parser->stackCount = 1;
73
4.75k
        break;
74
75
2.15k
    case 1:
76
2.15k
        parser->stackTwo = digit;
77
2.15k
        parser->stackCount = 2;
78
2.15k
        break;
79
80
433
    case 2:
81
433
        parser->stackThree = digit;
82
433
        parser->stackCount = 3;
83
433
        break;
84
85
0
    default:;
86
7.33k
    }
87
7.33k
}