OpenCoverage

shmbchar.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/lib/sh/shmbchar.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5const unsigned int is_basic_table [-
6 (0x7f * 2 + 1) -
7 / 32 + 1] =-
8{-
9 0x00001a00,-
10 0xffffffef,-
11 0xfffffffe,-
12 0x7ffffffe-
13-
14};-
15-
16-
17-
18extern int locale_utf8locale;-
19-
20-
21-
22static inline size_t-
23utf8_mbstrlen(s)-
24 const char *s;-
25{-
26 size_t num = 0;-
27 register unsigned char c;-
28-
29 while ((
(c = *s++)Description
TRUEnever evaluated
FALSEnever evaluated
c = *s++)
(c = *s++)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
30-
31 if ((
(c & 0xc0) != 0x80Description
TRUEnever evaluated
FALSEnever evaluated
c & 0xc0) != 0x80
(c & 0xc0) != 0x80Description
TRUEnever evaluated
FALSEnever evaluated
)
0
32 ++
never executed: ++num;
num;
never executed: ++num;
0
33 return
never executed: return (num);
(num);
never executed: return (num);
0
34}-
35-
36-
37static inline int-
38utf8_mblen (s, n)-
39 const char *s;-
40 int n;-
41{-
42 unsigned char c;-
43-
44 if (s == 0
s == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
45 return
never executed: return 0;
0;
never executed: return 0;
0
46 else if (n == 0
n == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
47 return
never executed: return -1;
-1;
never executed: return -1;
0
48-
49 c = (unsigned char) *s;-
50 if (c < 0x80
c < 0x80Description
TRUEnever evaluated
FALSEnever evaluated
)
0
51 return
never executed: return (c != 0);
(c != 0);
never executed: return (c != 0);
0
52 else if (c < 0xc0
c < 0xc0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
53 goto
never executed: goto return_error;
return_error;
never executed: goto return_error;
0
54 else-
55 {-
56 const char *start = s;-
57 size_t count;-
58 int check_unsafe;-
59-
60 if (c < 0xe0
c < 0xe0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
61 {-
62 count = 1;-
63 if (c < 0xc2
c < 0xc2Description
TRUEnever evaluated
FALSEnever evaluated
)
0
64 goto
never executed: goto return_error;
return_error;
never executed: goto return_error;
0
65 check_unsafe = 0;-
66 }
never executed: end of block
0
67 else if (c < 0xf0
c < 0xf0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
68 {-
69 count = 2;-
70 check_unsafe = (c == 0xe0);-
71 }
never executed: end of block
0
72-
73 else if (c < 0xf8
c < 0xf8Description
TRUEnever evaluated
FALSEnever evaluated
)
0
74 {-
75 count = 3;-
76 check_unsafe = (c == 0xe0);-
77 }
never executed: end of block
0
78 else if (c < 0xfc
c < 0xfcDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
79 {-
80 count = 4;-
81 check_unsafe = (c == 0xf8);-
82 }
never executed: end of block
0
83 else if (c < 0xfe
c < 0xfeDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
84 {-
85 count = 5;-
86 check_unsafe = (c == 0xfc);-
87 }
never executed: end of block
0
88-
89 else-
90 goto
never executed: goto return_error;
return_error;
never executed: goto return_error;
0
91 if (n <= count
n <= countDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
92 return
never executed: return -1;
-1;
never executed: return -1;
0
93 s++;-
94 c = (unsigned char) *s++ ^ 0x80;-
95 if (c >= 0x40
c >= 0x40Description
TRUEnever evaluated
FALSEnever evaluated
)
0
96 goto
never executed: goto return_error;
return_error;
never executed: goto return_error;
0
97 if (--
--count > 0Description
TRUEnever evaluated
FALSEnever evaluated
count > 0
--count > 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
98 {-
99 if (check_unsafe
check_unsafeDescription
TRUEnever evaluated
FALSEnever evaluated
&& ((
((c >> (6 - count)) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
c >> (6 - count)) == 0)
((c >> (6 - count)) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
100 goto
never executed: goto return_error;
return_error;
never executed: goto return_error;
0
101 do-
102 {-
103 c = (unsigned char) *s++ ^ 0x80;-
104 if (c >= 0x40
c >= 0x40Description
TRUEnever evaluated
FALSEnever evaluated
)
0
105 goto
never executed: goto return_error;
return_error;
never executed: goto return_error;
0
106 }
never executed: end of block
0
107 while (--
--count > 0Description
TRUEnever evaluated
FALSEnever evaluated
count > 0
--count > 0Description
TRUEnever evaluated
FALSEnever evaluated
);
0
108 }
never executed: end of block
0
109 return
never executed: return s - start;
s - start;
never executed: return s - start;
0
110 }-
111return_error:-
112 -
113 (*__errno_location ()) -
114 = -
115 84-
116 ;-
117 return
never executed: return -1;
-1;
never executed: return -1;
0
118}-
119-
120-
121-
122size_t-
123mbstrlen (s)-
124 const char *s;-
125{-
126 size_t clen, nc;-
127 mbstate_t mbs = { 0 }, mbsbak = { 0 };-
128 int f, mb_cur_max;-
129-
130 nc = 0;-
131 mb_cur_max = -
132 (__ctype_get_mb_cur_max ())-
133 ;-
134 while (*
*sDescription
TRUEevaluated 7495 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 650 times by 1 test
Evaluated by:
  • Self test
s
*sDescription
TRUEevaluated 7495 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 650 times by 1 test
Evaluated by:
  • Self test
&& (
(clen = (f = i...x, &mbs)) != 0Description
TRUEevaluated 7495 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
clen = (
(f = is_basic (*s))Description
TRUEevaluated 7174 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 321 times by 1 test
Evaluated by:
  • Self test
f = is_basic (*s))
(f = is_basic (*s))Description
TRUEevaluated 7174 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 321 times by 1 test
Evaluated by:
  • Self test
? 1 : mbrlen(s, mb_cur_max, &mbs)) != 0
(clen = (f = i...x, &mbs)) != 0Description
TRUEevaluated 7495 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
)
0-7495
135 {-
136 if (((
(clen) == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 7495 times by 1 test
Evaluated by:
  • Self test
clen) == (size_t)-1
(clen) == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 7495 times by 1 test
Evaluated by:
  • Self test
|| (
(clen) == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 7495 times by 1 test
Evaluated by:
  • Self test
clen) == (size_t)-2
(clen) == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 7495 times by 1 test
Evaluated by:
  • Self test
))
0-7495
137 {-
138 clen = 1;-
139 mbs = mbsbak;-
140 }
never executed: end of block
0
141-
142 if (f == 0
f == 0Description
TRUEevaluated 321 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7174 times by 1 test
Evaluated by:
  • Self test
)
321-7174
143 mbsbak = mbs;
executed 321 times by 1 test: mbsbak = mbs;
Executed by:
  • Self test
321
144-
145 s += clen;-
146 nc++;-
147 }
executed 7495 times by 1 test: end of block
Executed by:
  • Self test
7495
148 return
executed 650 times by 1 test: return nc;
Executed by:
  • Self test
nc;
executed 650 times by 1 test: return nc;
Executed by:
  • Self test
650
149}-
150-
151static inline char *-
152utf8_mbsmbchar (str)-
153 const char *str;-
154{-
155 register char *s;-
156-
157 for (s = (char *)str; *
*sDescription
TRUEevaluated 678369198 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 98412726 times by 1 test
Evaluated by:
  • Self test
s
*sDescription
TRUEevaluated 678369198 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 98412726 times by 1 test
Evaluated by:
  • Self test
; s++)
98412726-678369198
158 if ((*
(*s & 0xc0) == 0x80Description
TRUEevaluated 19 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 678369179 times by 1 test
Evaluated by:
  • Self test
s & 0xc0) == 0x80
(*s & 0xc0) == 0x80Description
TRUEevaluated 19 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 678369179 times by 1 test
Evaluated by:
  • Self test
)
19-678369179
159 return
executed 19 times by 1 test: return s;
Executed by:
  • Self test
s;
executed 19 times by 1 test: return s;
Executed by:
  • Self test
19
160 return
executed 98412726 times by 1 test: return (0);
Executed by:
  • Self test
(0);
executed 98412726 times by 1 test: return (0);
Executed by:
  • Self test
98412726
161}-
162-
163-
164-
165-
166char *-
167mbsmbchar (s)-
168 const char *s;-
169{-
170 char *t;-
171 size_t clen;-
172 mbstate_t mbs = { 0 };-
173 int mb_cur_max;-
174-
175 if (locale_utf8locale
locale_utf8localeDescription
TRUEevaluated 98412745 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4506 times by 1 test
Evaluated by:
  • Self test
)
4506-98412745
176 return
executed 98412745 times by 1 test: return (utf8_mbsmbchar (s));
Executed by:
  • Self test
(utf8_mbsmbchar (s));
executed 98412745 times by 1 test: return (utf8_mbsmbchar (s));
Executed by:
  • Self test
98412745
177-
178 mb_cur_max = -
179 (__ctype_get_mb_cur_max ())-
180 ;-
181 for (t = (char *)s; *
*tDescription
TRUEevaluated 40022 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4506 times by 1 test
Evaluated by:
  • Self test
t
*tDescription
TRUEevaluated 40022 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4506 times by 1 test
Evaluated by:
  • Self test
; t++)
4506-40022
182 {-
183 if (is_basic (*t)
is_basic (*t)Description
TRUEevaluated 39796 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 226 times by 1 test
Evaluated by:
  • Self test
)
226-39796
184 continue;
executed 39796 times by 1 test: continue;
Executed by:
  • Self test
39796
185-
186 if (locale_utf8locale
locale_utf8localeDescription
TRUEnever evaluated
FALSEevaluated 226 times by 1 test
Evaluated by:
  • Self test
)
0-226
187 clen = utf8_mblen (t, mb_cur_max);
never executed: clen = utf8_mblen (t, mb_cur_max);
0
188 else-
189 clen = mbrlen (t, mb_cur_max, &mbs);
executed 226 times by 1 test: clen = mbrlen (t, mb_cur_max, &mbs);
Executed by:
  • Self test
226
190-
191 if (clen == 0
clen == 0Description
TRUEnever evaluated
FALSEevaluated 226 times by 1 test
Evaluated by:
  • Self test
)
0-226
192 return
never executed: return 0;
0;
never executed: return 0;
0
193 if (((
(clen) == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 226 times by 1 test
Evaluated by:
  • Self test
clen) == (size_t)-1
(clen) == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 226 times by 1 test
Evaluated by:
  • Self test
|| (
(clen) == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 226 times by 1 test
Evaluated by:
  • Self test
clen) == (size_t)-2
(clen) == (size_t)-2Description
TRUEnever evaluated
FALSEevaluated 226 times by 1 test
Evaluated by:
  • Self test
))
0-226
194 continue;
never executed: continue;
0
195-
196 if (clen > 1
clen > 1Description
TRUEnever evaluated
FALSEevaluated 226 times by 1 test
Evaluated by:
  • Self test
)
0-226
197 return
never executed: return t;
t;
never executed: return t;
0
198 }
executed 226 times by 1 test: end of block
Executed by:
  • Self test
226
199 return
executed 4506 times by 1 test: return 0;
Executed by:
  • Self test
0;
executed 4506 times by 1 test: return 0;
Executed by:
  • Self test
4506
200}-
201-
202static inline int-
203utf_mbsnlen(src, srclen, maxlen)-
204 const char *src;-
205 size_t srclen;-
206 int maxlen;-
207{-
208 register int sind, count;-
209-
210 for (sind = count = 0; src[sind]
src[sind]Description
TRUEnever evaluated
FALSEnever evaluated
&& sind <= maxlen
sind <= maxlenDescription
TRUEnever evaluated
FALSEnever evaluated
; sind++)
0
211 {-
212 if ((
(src[sind] & 0xc0) != 0x80Description
TRUEnever evaluated
FALSEnever evaluated
src[sind] & 0xc0) != 0x80
(src[sind] & 0xc0) != 0x80Description
TRUEnever evaluated
FALSEnever evaluated
)
0
213 count++;
never executed: count++;
0
214 }
never executed: end of block
0
215 return
never executed: return (count);
(count);
never executed: return (count);
0
216}-
217-
218int-
219sh_mbsnlen(src, srclen, maxlen)-
220 const char *src;-
221 size_t srclen;-
222 int maxlen;-
223{-
224 int count;-
225 int sind;-
226 mbstate_t state; memset (&state, '\0', sizeof (mbstate_t));-
227-
228 for (sind = count = 0; src[sind]
src[sind]Description
TRUEnever evaluated
FALSEnever evaluated
; )
0
229 {-
230 count++;-
231 do { if (locale_mb_cur_max > 1
locale_mb_cur_max > 1Description
TRUEnever evaluated
FALSEnever evaluated
) { mbstate_t state_bak; size_t mblength; int _f; _f = is_basic ((src)[sind]); if (_f
_fDescription
TRUEnever evaluated
FALSEnever evaluated
) mblength = 1;
never executed: mblength = 1;
else if (locale_utf8locale
locale_utf8localeDescription
TRUEnever evaluated
FALSEnever evaluated
&& (((
(((src)[sind] & 0x80) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
src)[sind] & 0x80) == 0)
(((src)[sind] & 0x80) == 0)Description
TRUEnever evaluated
FALSEnever evaluated
) mblength = 1;
never executed: mblength = 1;
else { state_bak = state; mblength = mbrlen ((src) + (sind), (srclen) - (sind), &state); }
never executed: end of block
if (mblength == (size_t)-2
mblength == (size_t)-2Description
TRUEnever evaluated
FALSEnever evaluated
|| mblength == (size_t)-1
mblength == (size_t)-1Description
TRUEnever evaluated
FALSEnever evaluated
) { state = state_bak; (sind)++; }
never executed: end of block
else if (mblength == 0
mblength == 0Description
TRUEnever evaluated
FALSEnever evaluated
) (
never executed: (sind)++;
sind)++;
never executed: (sind)++;
else (
never executed: (sind) += mblength;
sind) += mblength;
never executed: (sind) += mblength;
} else (
never executed: (sind)++;
sind)++;
never executed: (sind)++;
} while (0);
0
232 if (sind > maxlen
sind > maxlenDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
233 break;
never executed: break;
0
234 }
never executed: end of block
0
235-
236 return
never executed: return count;
count;
never executed: return count;
0
237}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.1.2