Coverage Report

Created: 2026-12-04 06:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pcre2/src/pcre2_string_utils.c
Line
Count
Source
1
/*************************************************
2
*      Perl-Compatible Regular Expressions       *
3
*************************************************/
4
5
/* PCRE is a library of functions to support regular expressions whose syntax
6
and semantics are as close as possible to those of the Perl 5 language.
7
8
                       Written by Philip Hazel
9
     Original API code Copyright (c) 1997-2012 University of Cambridge
10
          New API code Copyright (c) 2018-2021 University of Cambridge
11
12
-----------------------------------------------------------------------------
13
Redistribution and use in source and binary forms, with or without
14
modification, are permitted provided that the following conditions are met:
15
16
    * Redistributions of source code must retain the above copyright notice,
17
      this list of conditions and the following disclaimer.
18
19
    * Redistributions in binary form must reproduce the above copyright
20
      notice, this list of conditions and the following disclaimer in the
21
      documentation and/or other materials provided with the distribution.
22
23
    * Neither the name of the University of Cambridge nor the names of its
24
      contributors may be used to endorse or promote products derived from
25
      this software without specific prior written permission.
26
27
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37
POSSIBILITY OF SUCH DAMAGE.
38
-----------------------------------------------------------------------------
39
*/
40
41
42
/* This module contains internal functions for comparing and finding the length
43
of strings. These are used instead of strcmp() etc because the standard
44
functions work only on 8-bit data. */
45
46
47
#include "pcre2_internal.h"
48
49
50
51
/*************************************************
52
*    Compare two zero-terminated PCRE2 strings   *
53
*************************************************/
54
55
/*
56
Arguments:
57
  str1        first string
58
  str2        second string
59
60
Returns:      0, 1, or -1
61
*/
62
63
int
64
PRIV(strcmp)(PCRE2_SPTR str1, PCRE2_SPTR str2)
65
126k
{
66
126k
  PCRE2_UCHAR c1, c2;
67
144k
  while (*str1 != '\0' || *str2 != '\0')
68
135k
  {
69
135k
    c1 = *str1++;
70
135k
    c2 = *str2++;
71
135k
    if (c1 != c2)
72
117k
      return ((c1 > c2) << 1) - 1;
73
135k
  }
74
75
8.76k
  return 0;
76
126k
}
_pcre2_strcmp_8
Line
Count
Source
65
58.2k
{
66
58.2k
  PCRE2_UCHAR c1, c2;
67
74.5k
  while (*str1 != '\0' || *str2 != '\0')
68
70.6k
  {
69
70.6k
    c1 = *str1++;
70
70.6k
    c2 = *str2++;
71
70.6k
    if (c1 != c2)
72
54.2k
      return ((c1 > c2) << 1) - 1;
73
70.6k
  }
74
75
3.90k
  return 0;
76
58.2k
}
_pcre2_strcmp_32
Line
Count
Source
65
49.9k
{
66
49.9k
  PCRE2_UCHAR c1, c2;
67
50.9k
  while (*str1 != '\0' || *str2 != '\0')
68
50.3k
  {
69
50.3k
    c1 = *str1++;
70
50.3k
    c2 = *str2++;
71
50.3k
    if (c1 != c2)
72
49.2k
      return ((c1 > c2) << 1) - 1;
73
50.3k
  }
74
75
666
  return 0;
76
49.9k
}
_pcre2_strcmp_16
Line
Count
Source
65
17.8k
{
66
17.8k
  PCRE2_UCHAR c1, c2;
67
19.1k
  while (*str1 != '\0' || *str2 != '\0')
68
14.9k
  {
69
14.9k
    c1 = *str1++;
70
14.9k
    c2 = *str2++;
71
14.9k
    if (c1 != c2)
72
13.6k
      return ((c1 > c2) << 1) - 1;
73
14.9k
  }
74
75
4.19k
  return 0;
76
17.8k
}
77
78
79
/*************************************************
80
*  Compare zero-terminated PCRE2 & 8-bit strings *
81
*************************************************/
82
83
/* As the 8-bit string is almost always a literal, its type is specified as
84
const char *.
85
86
Arguments:
87
  str1        first string
88
  str2        second string
89
90
Returns:      0, 1, or -1
91
*/
92
93
int
94
PRIV(strcmp_c8)(PCRE2_SPTR str1, const char *str2)
95
1.16M
{
96
1.16M
  PCRE2_UCHAR c1, c2;
97
2.09M
  while (*str1 != '\0' || *str2 != '\0')
98
1.94M
  {
99
1.94M
    c1 = *str1++;
100
1.94M
    c2 = *str2++;
101
1.94M
    if (c1 != c2)
102
1.00M
      return ((c1 > c2) << 1) - 1;
103
1.94M
  }
104
105
155k
  return 0;
106
1.16M
}
_pcre2_strcmp_c8_8
Line
Count
Source
95
566k
{
96
566k
  PCRE2_UCHAR c1, c2;
97
1.03M
  while (*str1 != '\0' || *str2 != '\0')
98
957k
  {
99
957k
    c1 = *str1++;
100
957k
    c2 = *str2++;
101
957k
    if (c1 != c2)
102
490k
      return ((c1 > c2) << 1) - 1;
103
957k
  }
104
105
76.1k
  return 0;
106
566k
}
_pcre2_strcmp_c8_32
Line
Count
Source
95
297k
{
96
297k
  PCRE2_UCHAR c1, c2;
97
527k
  while (*str1 != '\0' || *str2 != '\0')
98
488k
  {
99
488k
    c1 = *str1++;
100
488k
    c2 = *str2++;
101
488k
    if (c1 != c2)
102
258k
      return ((c1 > c2) << 1) - 1;
103
488k
  }
104
105
38.9k
  return 0;
106
297k
}
_pcre2_strcmp_c8_16
Line
Count
Source
95
300k
{
96
300k
  PCRE2_UCHAR c1, c2;
97
535k
  while (*str1 != '\0' || *str2 != '\0')
98
495k
  {
99
495k
    c1 = *str1++;
100
495k
    c2 = *str2++;
101
495k
    if (c1 != c2)
102
260k
      return ((c1 > c2) << 1) - 1;
103
495k
  }
104
105
40.0k
  return 0;
106
300k
}
107
108
109
/*************************************************
110
*    Compare two PCRE2 strings, given a length   *
111
*************************************************/
112
113
/*
114
Arguments:
115
  str1        first string
116
  str2        second string
117
  len         the length
118
119
Returns:      0, 1, or -1
120
*/
121
122
int
123
PRIV(strncmp)(PCRE2_SPTR str1, PCRE2_SPTR str2, size_t len)
124
27.2M
{
125
27.2M
  PCRE2_UCHAR c1, c2;
126
41.5M
  for (; len > 0; len--)
127
27.3M
  {
128
27.3M
    c1 = *str1++;
129
27.3M
    c2 = *str2++;
130
27.3M
    if (c1 != c2)
131
13.0M
      return ((c1 > c2) << 1) - 1;
132
27.3M
  }
133
134
14.2M
  return 0;
135
27.2M
}
_pcre2_strncmp_8
Line
Count
Source
124
26.6M
{
125
26.6M
  PCRE2_UCHAR c1, c2;
126
40.4M
  for (; len > 0; len--)
127
26.7M
  {
128
26.7M
    c1 = *str1++;
129
26.7M
    c2 = *str2++;
130
26.7M
    if (c1 != c2)
131
12.9M
      return ((c1 > c2) << 1) - 1;
132
26.7M
  }
133
134
13.7M
  return 0;
135
26.6M
}
_pcre2_strncmp_32
Line
Count
Source
124
184k
{
125
184k
  PCRE2_UCHAR c1, c2;
126
362k
  for (; len > 0; len--)
127
186k
  {
128
186k
    c1 = *str1++;
129
186k
    c2 = *str2++;
130
186k
    if (c1 != c2)
131
8.06k
      return ((c1 > c2) << 1) - 1;
132
186k
  }
133
134
176k
  return 0;
135
184k
}
_pcre2_strncmp_16
Line
Count
Source
124
367k
{
125
367k
  PCRE2_UCHAR c1, c2;
126
711k
  for (; len > 0; len--)
127
369k
  {
128
369k
    c1 = *str1++;
129
369k
    c2 = *str2++;
130
369k
    if (c1 != c2)
131
25.8k
      return ((c1 > c2) << 1) - 1;
132
369k
  }
133
134
341k
  return 0;
135
367k
}
136
137
138
/*************************************************
139
* Compare PCRE2 string to 8-bit string by length *
140
*************************************************/
141
142
/* As the 8-bit string is almost always a literal, its type is specified as
143
const char *.
144
145
Arguments:
146
  str1        first string
147
  str2        second string
148
  len         the length
149
150
Returns:      0, 1, or -1
151
*/
152
153
int
154
PRIV(strncmp_c8)(PCRE2_SPTR str1, const char *str2, size_t len)
155
3.66M
{
156
3.66M
  PCRE2_UCHAR c1, c2;
157
5.83M
  for (; len > 0; len--)
158
5.42M
  {
159
5.42M
    c1 = *str1++;
160
5.42M
    c2 = *str2++;
161
5.42M
    if (c1 != c2)
162
3.25M
      return ((c1 > c2) << 1) - 1;
163
5.42M
  }
164
165
408k
  return 0;
166
3.66M
}
_pcre2_strncmp_c8_8
Line
Count
Source
155
1.87M
{
156
1.87M
  PCRE2_UCHAR c1, c2;
157
2.91M
  for (; len > 0; len--)
158
2.72M
  {
159
2.72M
    c1 = *str1++;
160
2.72M
    c2 = *str2++;
161
2.72M
    if (c1 != c2)
162
1.68M
      return ((c1 > c2) << 1) - 1;
163
2.72M
  }
164
165
187k
  return 0;
166
1.87M
}
_pcre2_strncmp_c8_32
Line
Count
Source
155
793k
{
156
793k
  PCRE2_UCHAR c1, c2;
157
1.26M
  for (; len > 0; len--)
158
1.17M
  {
159
1.17M
    c1 = *str1++;
160
1.17M
    c2 = *str2++;
161
1.17M
    if (c1 != c2)
162
698k
      return ((c1 > c2) << 1) - 1;
163
1.17M
  }
164
165
95.2k
  return 0;
166
793k
}
_pcre2_strncmp_c8_16
Line
Count
Source
155
998k
{
156
998k
  PCRE2_UCHAR c1, c2;
157
1.64M
  for (; len > 0; len--)
158
1.52M
  {
159
1.52M
    c1 = *str1++;
160
1.52M
    c2 = *str2++;
161
1.52M
    if (c1 != c2)
162
872k
      return ((c1 > c2) << 1) - 1;
163
1.52M
  }
164
165
125k
  return 0;
166
998k
}
167
168
169
/*************************************************
170
*        Find the length of a PCRE2 string       *
171
*************************************************/
172
173
/*
174
Argument:    the string
175
Returns:     the length
176
*/
177
178
PCRE2_SIZE
179
PRIV(strlen)(PCRE2_SPTR str)
180
0
{
181
0
  PCRE2_SIZE c = 0;
182
0
  while (*str++ != 0)
183
0
    c++;
184
0
  return c;
185
0
}
Unexecuted instantiation: _pcre2_strlen_8
Unexecuted instantiation: _pcre2_strlen_32
Unexecuted instantiation: _pcre2_strlen_16
186
187
188
/*************************************************
189
* Copy 8-bit 0-terminated string to PCRE2 string *
190
*************************************************/
191
192
/* Arguments:
193
  str1     buffer to receive the string
194
  str2     8-bit string to be copied
195
196
Returns:   the number of code units used (excluding trailing zero)
197
*/
198
199
PCRE2_SIZE
200
PRIV(strcpy_c8)(PCRE2_UCHAR *str1, const char *str2)
201
0
{
202
0
  PCRE2_UCHAR *t = str1;
203
0
  while (*str2 != 0)
204
0
    *t++ = *str2++;
205
0
  *t = 0;
206
0
  return t - str1;
207
0
}
Unexecuted instantiation: _pcre2_strcpy_c8_8
Unexecuted instantiation: _pcre2_strcpy_c8_32
Unexecuted instantiation: _pcre2_strcpy_c8_16
208
209
/* End of pcre2_string_utils.c */