Coverage Report

Created: 2026-09-28 06:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/imagemagick/MagickCore/token-private.h
Line
Count
Source
1
/*
2
  Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization
3
  dedicated to making software imaging solutions freely available.
4
5
  You may not use this file except in compliance with the License.  You may
6
  obtain a copy of the License at
7
8
    https://imagemagick.org/license/
9
10
  Unless required by applicable law or agreed to in writing, software
11
  distributed under the License is distributed on an "AS IS" BASIS,
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
  See the License for the specific language governing permissions and
14
  limitations under the License.
15
16
  MagickCore private token methods.
17
*/
18
#ifndef MAGICKCORE_TOKEN_PRIVATE_H
19
#define MAGICKCORE_TOKEN_PRIVATE_H
20
21
#if defined(__cplusplus) || defined(c_plusplus)
22
extern "C" {
23
#endif
24
25
#ifndef EILSEQ
26
  #define EILSEQ  ENOENT
27
#endif
28
29
31.6M
#define MaxMultibyteCodes  6
30
31
extern MagickPrivate MagickBooleanType
32
  IsGlob(const char *) magick_attribute((__pure__));
33
34
typedef struct
35
{
36
  int
37
    code_mask,
38
    code_value,
39
    utf_mask,
40
    utf_value;
41
} UTFInfo;
42
43
static UTFInfo
44
  utf_info[MaxMultibyteCodes] =
45
  {
46
    { 0x80, 0x00, 0x000007f, 0x0000000 },  /* 1 byte sequence */
47
    { 0xE0, 0xC0, 0x00007ff, 0x0000080 },  /* 2 byte sequence */
48
    { 0xF0, 0xE0, 0x000ffff, 0x0000800 },  /* 3 byte sequence */
49
    { 0xF8, 0xF0, 0x01fffff, 0x0010000 },  /* 4 byte sequence */
50
    { 0xFC, 0xF8, 0x03fffff, 0x0200000 },  /* 5 byte sequence */
51
    { 0xFE, 0xFC, 0x7ffffff, 0x4000000 },  /* 6 byte sequence */
52
  };
53
54
static inline unsigned char *ConvertLatin1ToUTF8(
55
  const unsigned char *magick_restrict content)
56
0
{
57
0
  int
58
0
    c;
59
60
0
  const unsigned char
61
0
    *magick_restrict p;
62
63
0
  size_t
64
0
    length;
65
66
0
  unsigned char
67
0
    *magick_restrict q,
68
0
    *utf8;
69
70
0
  length=0;
71
0
  for (p=content; *p != '\0'; p++)
72
0
    length+=(*p & 0x80) != 0 ? 2 : 1;
73
0
  utf8=(unsigned char *) NULL;
74
0
  if (~length >= 1)
75
0
    utf8=(unsigned char *) AcquireQuantumMemory(length+1UL,sizeof(*utf8));
76
0
  if (utf8 == (unsigned char *) NULL)
77
0
    return((unsigned char *) NULL);
78
0
  q=utf8;
79
0
  for (p=content; *p != '\0'; p++)
80
0
  {
81
0
    c=(*p);
82
0
    if ((c & 0x80) == 0)
83
0
      *q++=(unsigned char) c;
84
0
    else
85
0
      {
86
0
        *q++=(unsigned char) (0xc0 | ((c >> 6) & 0x3f));
87
0
        *q++=(unsigned char) (0x80 | (c & 0x3f));
88
0
      }
89
0
  }
90
0
  *q='\0';
91
0
  return(utf8);
92
0
}
Unexecuted instantiation: annotate.c:ConvertLatin1ToUTF8
Unexecuted instantiation: delegate.c:ConvertLatin1ToUTF8
Unexecuted instantiation: image.c:ConvertLatin1ToUTF8
Unexecuted instantiation: property.c:ConvertLatin1ToUTF8
Unexecuted instantiation: token.c:ConvertLatin1ToUTF8
Unexecuted instantiation: utility.c:ConvertLatin1ToUTF8
Unexecuted instantiation: xml-tree.c:ConvertLatin1ToUTF8
93
94
static inline unsigned char *ConvertMacRomanToUTF8(
95
  const unsigned char *magick_restrict content)
96
0
{
97
0
  static const uint16_t macroman_unicode[128] = {
98
0
    0x00C4,0x00C5,0x00C7,0x00C9,0x00D1,0x00D6,0x00DC,0x00E1,
99
0
    0x00E0,0x00E2,0x00E4,0x00E3,0x00E5,0x00E7,0x00E9,0x00E8,
100
0
    0x00EA,0x00EB,0x00ED,0x00EC,0x00EE,0x00EF,0x00F1,0x00F3,
101
0
    0x00F2,0x00F4,0x00F6,0x00F5,0x00FA,0x00F9,0x00FB,0x00FC,
102
0
    0x2020,0x00B0,0x00A2,0x00A3,0x00A7,0x2022,0x00B6,0x00DF,
103
0
    0x00AE,0x00A9,0x2122,0x00B4,0x00A8,0x2260,0x00C6,0x00D8,
104
0
    0x221E,0x00B1,0x2264,0x2265,0x00A5,0x00B5,0x2202,0x2211,
105
0
    0x220F,0x03C0,0x222B,0x00AA,0x00BA,0x03A9,0x00E6,0x00F8,
106
0
    0x00BF,0x00A1,0x00AC,0x221A,0x0192,0x2248,0x2206,0x00AB,
107
0
    0x00BB,0x2026,0x00A0,0x00C0,0x00C3,0x00D5,0x0152,0x0153,
108
0
    0x2013,0x2014,0x201C,0x201D,0x2018,0x2019,0x00F7,0x25CA,
109
0
    0x00FF,0x0178,0x2044,0x20AC,0x2039,0x203A,0xFB01,0xFB02,
110
0
    0x2021,0x00B7,0x201A,0x201E,0x2030,0x00C2,0x00CA,0x00C1,
111
0
    0x00CB,0x00C8,0x00CD,0x00CE,0x00CF,0x00CC,0x00D3,0x00D4,
112
0
    0xF8FF,0x00D2,0x00DA,0x00DB,0x00D9,0x0131,0x02C6,0x02DC,
113
0
    0x00AF,0x02D8,0x02D9,0x02DA,0x00B8,0x02DD,0x02DB,0x02C7
114
0
  };
115
116
0
  int
117
0
    c;
118
119
0
  const unsigned char
120
0
    *magick_restrict p;
121
122
0
  size_t
123
0
    length;
124
125
0
  unsigned char
126
0
    *magick_restrict q,
127
0
    *utf8;
128
129
0
  length=0;
130
0
  for (p=content; *p != '\0'; p++)
131
0
    length+=(*p & 0x80) != 0 ? 4 : 1;
132
0
  utf8=(unsigned char *) NULL;
133
0
  if (~length >= 1)
134
0
    utf8=(unsigned char *) AcquireQuantumMemory(length+1UL,sizeof(*utf8));
135
0
  if (utf8 == (unsigned char *) NULL)
136
0
    return((unsigned char *) NULL);
137
0
  q=utf8;
138
0
  for (p=content; *p != '\0'; p++)
139
0
  {
140
0
    c=(*p);
141
0
    if (c > 128)
142
0
      c=(int) macroman_unicode[c-128];
143
0
    if ((c & 0x80) == 0)
144
0
      *q++=(unsigned char) c;
145
0
    else
146
0
      if (c <= 0x7ff)
147
0
        {
148
0
          *q++=(unsigned char) (0xc0 | ((c >> 6) & 0x3f));
149
0
          *q++=(unsigned char) (0x80 | (c & 0x3f));
150
0
        }
151
0
      else
152
0
        if (c <= 0xffff)
153
0
          {
154
0
            *q++=(unsigned char) (0xe0 | (c >> 12));
155
0
            *q++=(unsigned char) (0x80 | ((c >> 6) & 0x3f));
156
0
            *q++=(unsigned char) (0x80 | (c & 0x3f));
157
0
          }
158
0
        else
159
0
          {
160
0
            *q++=(unsigned char) (0xf0 | (c >> 18));
161
0
            *q++=(unsigned char) (0x80 | ((c >> 12) & 0x3f));
162
0
            *q++=(unsigned char) (0x80 | ((c >> 6) & 0x3f));
163
0
            *q++=(unsigned char) (0x80 | (c & 0x3f));
164
0
          }
165
0
  }
166
0
  *q='\0';
167
0
  return(utf8);
168
0
}
Unexecuted instantiation: annotate.c:ConvertMacRomanToUTF8
Unexecuted instantiation: delegate.c:ConvertMacRomanToUTF8
Unexecuted instantiation: image.c:ConvertMacRomanToUTF8
Unexecuted instantiation: property.c:ConvertMacRomanToUTF8
Unexecuted instantiation: token.c:ConvertMacRomanToUTF8
Unexecuted instantiation: utility.c:ConvertMacRomanToUTF8
Unexecuted instantiation: xml-tree.c:ConvertMacRomanToUTF8
169
170
static inline int GetNextUTFCode(const char *magick_restrict text,
171
  unsigned int *magick_restrict octets)
172
31.3M
{
173
31.3M
  int
174
31.3M
    code;
175
176
31.3M
  ssize_t
177
31.3M
    i;
178
179
31.3M
  int
180
31.3M
    c,
181
31.3M
    unicode;
182
183
31.3M
  *octets=1;
184
31.3M
  if (text == (const char *) NULL)
185
0
    {
186
0
      errno=EINVAL;
187
0
      return(-1);
188
0
    }
189
31.3M
  code=(int) (*text++) & 0xff;
190
31.3M
  unicode=code;
191
31.6M
  for (i=0; i < MaxMultibyteCodes; i++)
192
31.6M
  {
193
31.6M
    if ((code & utf_info[i].code_mask) == utf_info[i].code_value)
194
31.0M
      {
195
31.0M
        unicode&=utf_info[i].utf_mask;
196
31.0M
        if (unicode < utf_info[i].utf_value)
197
31.1k
          break;
198
31.0M
        *octets=(unsigned int) (i+1);
199
31.0M
        return(unicode);
200
31.0M
      }
201
522k
    c=(int) (*text++ ^ 0x80) & 0xff;
202
522k
    if ((c & 0xc0) != 0)
203
202k
      break;
204
319k
    if (unicode > 0x10FFFF)
205
32.0k
      break;
206
287k
    unicode=(unicode << 6) | c;
207
287k
  }
208
31.3M
  errno=EILSEQ;
209
265k
  return(-1);
210
31.3M
}
annotate.c:GetNextUTFCode
Line
Count
Source
172
29.8M
{
173
29.8M
  int
174
29.8M
    code;
175
176
29.8M
  ssize_t
177
29.8M
    i;
178
179
29.8M
  int
180
29.8M
    c,
181
29.8M
    unicode;
182
183
29.8M
  *octets=1;
184
29.8M
  if (text == (const char *) NULL)
185
0
    {
186
0
      errno=EINVAL;
187
0
      return(-1);
188
0
    }
189
29.8M
  code=(int) (*text++) & 0xff;
190
29.8M
  unicode=code;
191
29.8M
  for (i=0; i < MaxMultibyteCodes; i++)
192
29.8M
  {
193
29.8M
    if ((code & utf_info[i].code_mask) == utf_info[i].code_value)
194
29.8M
      {
195
29.8M
        unicode&=utf_info[i].utf_mask;
196
29.8M
        if (unicode < utf_info[i].utf_value)
197
0
          break;
198
29.8M
        *octets=(unsigned int) (i+1);
199
29.8M
        return(unicode);
200
29.8M
      }
201
0
    c=(int) (*text++ ^ 0x80) & 0xff;
202
0
    if ((c & 0xc0) != 0)
203
0
      break;
204
0
    if (unicode > 0x10FFFF)
205
0
      break;
206
0
    unicode=(unicode << 6) | c;
207
0
  }
208
29.8M
  errno=EILSEQ;
209
0
  return(-1);
210
29.8M
}
Unexecuted instantiation: delegate.c:GetNextUTFCode
Unexecuted instantiation: image.c:GetNextUTFCode
Unexecuted instantiation: property.c:GetNextUTFCode
token.c:GetNextUTFCode
Line
Count
Source
172
1.44M
{
173
1.44M
  int
174
1.44M
    code;
175
176
1.44M
  ssize_t
177
1.44M
    i;
178
179
1.44M
  int
180
1.44M
    c,
181
1.44M
    unicode;
182
183
1.44M
  *octets=1;
184
1.44M
  if (text == (const char *) NULL)
185
0
    {
186
0
      errno=EINVAL;
187
0
      return(-1);
188
0
    }
189
1.44M
  code=(int) (*text++) & 0xff;
190
1.44M
  unicode=code;
191
1.72M
  for (i=0; i < MaxMultibyteCodes; i++)
192
1.72M
  {
193
1.72M
    if ((code & utf_info[i].code_mask) == utf_info[i].code_value)
194
1.20M
      {
195
1.20M
        unicode&=utf_info[i].utf_mask;
196
1.20M
        if (unicode < utf_info[i].utf_value)
197
31.1k
          break;
198
1.17M
        *octets=(unsigned int) (i+1);
199
1.17M
        return(unicode);
200
1.20M
      }
201
522k
    c=(int) (*text++ ^ 0x80) & 0xff;
202
522k
    if ((c & 0xc0) != 0)
203
202k
      break;
204
319k
    if (unicode > 0x10FFFF)
205
32.0k
      break;
206
287k
    unicode=(unicode << 6) | c;
207
287k
  }
208
1.44M
  errno=EILSEQ;
209
265k
  return(-1);
210
1.44M
}
Unexecuted instantiation: utility.c:GetNextUTFCode
Unexecuted instantiation: xml-tree.c:GetNextUTFCode
211
212
static inline int GetUTFCode(const char *magick_restrict text)
213
22.3M
{
214
22.3M
  unsigned int
215
22.3M
    octets;
216
217
22.3M
  return(GetNextUTFCode(text,&octets));
218
22.3M
}
annotate.c:GetUTFCode
Line
Count
Source
213
21.2M
{
214
21.2M
  unsigned int
215
21.2M
    octets;
216
217
21.2M
  return(GetNextUTFCode(text,&octets));
218
21.2M
}
Unexecuted instantiation: delegate.c:GetUTFCode
Unexecuted instantiation: image.c:GetUTFCode
Unexecuted instantiation: property.c:GetUTFCode
token.c:GetUTFCode
Line
Count
Source
213
1.08M
{
214
1.08M
  unsigned int
215
1.08M
    octets;
216
217
1.08M
  return(GetNextUTFCode(text,&octets));
218
1.08M
}
Unexecuted instantiation: utility.c:GetUTFCode
Unexecuted instantiation: xml-tree.c:GetUTFCode
219
220
static inline unsigned int GetUTFOctets(const char *magick_restrict text)
221
9.00M
{
222
9.00M
  unsigned int
223
9.00M
    octets;
224
225
9.00M
  (void) GetNextUTFCode(text,&octets);
226
9.00M
  return(octets);
227
9.00M
}
annotate.c:GetUTFOctets
Line
Count
Source
221
8.64M
{
222
8.64M
  unsigned int
223
8.64M
    octets;
224
225
8.64M
  (void) GetNextUTFCode(text,&octets);
226
8.64M
  return(octets);
227
8.64M
}
Unexecuted instantiation: delegate.c:GetUTFOctets
Unexecuted instantiation: image.c:GetUTFOctets
Unexecuted instantiation: property.c:GetUTFOctets
token.c:GetUTFOctets
Line
Count
Source
221
358k
{
222
358k
  unsigned int
223
358k
    octets;
224
225
358k
  (void) GetNextUTFCode(text,&octets);
226
358k
  return(octets);
227
358k
}
Unexecuted instantiation: utility.c:GetUTFOctets
Unexecuted instantiation: xml-tree.c:GetUTFOctets
228
229
static inline MagickBooleanType IsNonBreakingUTFSpace(const int code)
230
0
{
231
0
  if (code == 0x00a0)
232
0
    return(MagickTrue);
233
0
  return(MagickFalse);
234
0
}
Unexecuted instantiation: annotate.c:IsNonBreakingUTFSpace
Unexecuted instantiation: delegate.c:IsNonBreakingUTFSpace
Unexecuted instantiation: image.c:IsNonBreakingUTFSpace
Unexecuted instantiation: property.c:IsNonBreakingUTFSpace
Unexecuted instantiation: token.c:IsNonBreakingUTFSpace
Unexecuted instantiation: utility.c:IsNonBreakingUTFSpace
Unexecuted instantiation: xml-tree.c:IsNonBreakingUTFSpace
235
236
static inline MagickBooleanType IsUTFSpace(const int code)
237
58
{
238
58
  if (((code >= 0x0009) && (code <= 0x000d)) || (code == 0x0020) ||
239
58
      (code == 0x0085) || (code == 0x00a0) || (code == 0x1680) ||
240
58
      (code == 0x180e) || ((code >= 0x2000) && (code <= 0x200a)) ||
241
58
      (code == 0x2028) || (code == 0x2029) || (code == 0x202f) ||
242
58
      (code == 0x205f) || (code == 0x3000))
243
0
    return(MagickTrue);
244
58
  return(MagickFalse);
245
58
}
annotate.c:IsUTFSpace
Line
Count
Source
237
58
{
238
58
  if (((code >= 0x0009) && (code <= 0x000d)) || (code == 0x0020) ||
239
58
      (code == 0x0085) || (code == 0x00a0) || (code == 0x1680) ||
240
58
      (code == 0x180e) || ((code >= 0x2000) && (code <= 0x200a)) ||
241
58
      (code == 0x2028) || (code == 0x2029) || (code == 0x202f) ||
242
58
      (code == 0x205f) || (code == 0x3000))
243
0
    return(MagickTrue);
244
58
  return(MagickFalse);
245
58
}
Unexecuted instantiation: delegate.c:IsUTFSpace
Unexecuted instantiation: image.c:IsUTFSpace
Unexecuted instantiation: property.c:IsUTFSpace
Unexecuted instantiation: token.c:IsUTFSpace
Unexecuted instantiation: utility.c:IsUTFSpace
Unexecuted instantiation: xml-tree.c:IsUTFSpace
246
247
static inline MagickBooleanType IsUTFValid(int code)
248
0
{
249
0
  int
250
0
    mask;
251
0
252
0
  mask=(int) 0x7fffffff;
253
0
  if (((code & ~mask) != 0) && ((code < 0xd800) || (code > 0xdfff)) &&
254
0
      (code != 0xfffe) && (code != 0xffff))
255
0
    return(MagickFalse);
256
0
  return(MagickTrue);
257
0
}
Unexecuted instantiation: annotate.c:IsUTFValid
Unexecuted instantiation: delegate.c:IsUTFValid
Unexecuted instantiation: image.c:IsUTFValid
Unexecuted instantiation: property.c:IsUTFValid
Unexecuted instantiation: token.c:IsUTFValid
Unexecuted instantiation: utility.c:IsUTFValid
Unexecuted instantiation: xml-tree.c:IsUTFValid
258
259
static inline MagickBooleanType IsUTFAscii(int code)
260
0
{
261
0
  int
262
0
    mask;
263
0
264
0
  mask=(int) 0x7f;
265
0
  if ((code & ~mask) != 0)
266
0
    return(MagickFalse);
267
0
  return(MagickTrue);
268
0
}
Unexecuted instantiation: annotate.c:IsUTFAscii
Unexecuted instantiation: delegate.c:IsUTFAscii
Unexecuted instantiation: image.c:IsUTFAscii
Unexecuted instantiation: property.c:IsUTFAscii
Unexecuted instantiation: token.c:IsUTFAscii
Unexecuted instantiation: utility.c:IsUTFAscii
Unexecuted instantiation: xml-tree.c:IsUTFAscii
269
270
#if defined(__cplusplus) || defined(c_plusplus)
271
}
272
#endif
273
274
#endif