OpenCoverage

mbsalign.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/gl/lib/mbsalign.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4static -
5 _Bool-
6-
7wc_ensure_printable (wchar_t *wchars)-
8{-
9 -
10 _Bool -
11 replaced = -
12 0-
13 ;-
14 wchar_t *wc = wchars;-
15 while (*
*wcDescription
TRUEnever evaluated
FALSEnever evaluated
wc
*wcDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
16 {-
17 if (!iswprint ((wint_t) *wc)
!iswprint ((wint_t) *wc)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
18 {-
19 *wc = 0xFFFD;-
20 replaced = -
21 1-
22 ;-
23 }
never executed: end of block
0
24 wc++;-
25 }
never executed: end of block
0
26 return
never executed: return replaced;
replaced;
never executed: return replaced;
0
27}-
28-
29-
30-
31-
32static size_t-
33wc_truncate (wchar_t *wc, size_t width)-
34{-
35 size_t cells = 0;-
36 int next_cells = 0;-
37-
38 while (*
*wcDescription
TRUEnever evaluated
FALSEnever evaluated
wc
*wcDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
39 {-
40 next_cells = wcwidth (*wc);-
41 if (next_cells == -1
next_cells == -1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
42 {-
43 *wc = 0xFFFD;-
44 next_cells = 1;-
45 }
never executed: end of block
0
46 if (cells + next_cells > width
cells + next_cells > widthDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
47 break;
never executed: break;
0
48 cells += next_cells;-
49 wc++;-
50 }
never executed: end of block
0
51 *wc = L'\0';-
52 return
never executed: return cells;
cells;
never executed: return cells;
0
53}-
54-
55-
56-
57-
58-
59-
60static char*-
61mbs_align_pad (char *dest, const char* dest_end, size_t n_spaces)-
62{-
63-
64-
65 while (n_spaces--
n_spaces--Description
TRUEevaluated 119527 times by 4 tests
Evaluated by:
  • df
  • ls
  • numfmt
  • vdir
FALSEevaluated 10062 times by 4 tests
Evaluated by:
  • df
  • ls
  • numfmt
  • vdir
&& (
(dest < dest_end)Description
TRUEevaluated 119527 times by 4 tests
Evaluated by:
  • df
  • ls
  • numfmt
  • vdir
FALSEnever evaluated
dest < dest_end)
(dest < dest_end)Description
TRUEevaluated 119527 times by 4 tests
Evaluated by:
  • df
  • ls
  • numfmt
  • vdir
FALSEnever evaluated
)
0-119527
66 *
executed 119527 times by 4 tests: *dest++ = ' ';
Executed by:
  • df
  • ls
  • numfmt
  • vdir
dest++ = ' ';
executed 119527 times by 4 tests: *dest++ = ' ';
Executed by:
  • df
  • ls
  • numfmt
  • vdir
119527
67 *dest = '\0';-
68 return
executed 10062 times by 4 tests: return dest;
Executed by:
  • df
  • ls
  • numfmt
  • vdir
dest;
executed 10062 times by 4 tests: return dest;
Executed by:
  • df
  • ls
  • numfmt
  • vdir
10062
69}-
70size_t-
71mbsalign (const char *src, char *dest, size_t dest_size,-
72 size_t *width, mbs_align_t align, int flags)-
73{-
74 size_t ret = -
75 (18446744073709551615UL)-
76 ;-
77 size_t src_size = strlen (src) + 1;-
78 char *newstr = -
79 ((void *)0)-
80 ;-
81 wchar_t *str_wc = -
82 ((void *)0)-
83 ;-
84 const char *str_to_print = src;-
85 size_t n_cols = src_size - 1;-
86 size_t n_used_bytes = n_cols;-
87 size_t n_spaces = 0;-
88 -
89 _Bool -
90 conversion = -
91 0-
92 ;-
93 -
94 _Bool -
95 wc_enabled = -
96 0-
97 ;-
98-
99-
100-
101-
102 if (!(flags & MBA_UNIBYTE_ONLY)
!(flags & MBA_UNIBYTE_ONLY)Description
TRUEevaluated 5000 times by 3 tests
Evaluated by:
  • df
  • ls
  • vdir
FALSEevaluated 31 times by 1 test
Evaluated by:
  • numfmt
&&
31-5000
103 (
(__ctype_get_m...ur_max ()) > 1Description
TRUEnever evaluated
FALSEevaluated 5000 times by 3 tests
Evaluated by:
  • df
  • ls
  • vdir
__ctype_get_mb_cur_max ())
(__ctype_get_m...ur_max ()) > 1Description
TRUEnever evaluated
FALSEevaluated 5000 times by 3 tests
Evaluated by:
  • df
  • ls
  • vdir
0-5000
104 > 1
(__ctype_get_m...ur_max ()) > 1Description
TRUEnever evaluated
FALSEevaluated 5000 times by 3 tests
Evaluated by:
  • df
  • ls
  • vdir
)
0-5000
105 {-
106 size_t src_chars = mbstowcs (-
107 ((void *)0)-
108 , src, 0);-
109 if (src_chars ==
src_chars == (...73709551615UL)Description
TRUEnever evaluated
FALSEnever evaluated
0
110 (18446744073709551615UL)
src_chars == (...73709551615UL)Description
TRUEnever evaluated
FALSEnever evaluated
0
111 )-
112 {-
113 if (flags & MBA_UNIBYTE_FALLBACK
flags & MBA_UNIBYTE_FALLBACKDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
114 goto
never executed: goto mbsalign_unibyte;
mbsalign_unibyte;
never executed: goto mbsalign_unibyte;
0
115 else-
116 goto
never executed: goto mbsalign_cleanup;
mbsalign_cleanup;
never executed: goto mbsalign_cleanup;
0
117 }-
118 src_chars += 1;-
119 str_wc = malloc (src_chars * sizeof (wchar_t));-
120 if (str_wc ==
str_wc == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
121 ((void *)0)
str_wc == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
122 )-
123 {-
124 if (flags & MBA_UNIBYTE_FALLBACK
flags & MBA_UNIBYTE_FALLBACKDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
125 goto
never executed: goto mbsalign_unibyte;
mbsalign_unibyte;
never executed: goto mbsalign_unibyte;
0
126 else-
127 goto
never executed: goto mbsalign_cleanup;
mbsalign_cleanup;
never executed: goto mbsalign_cleanup;
0
128 }-
129 if (mbstowcs (str_wc, src, src_chars) != 0
mbstowcs (str_...rc_chars) != 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
130 {-
131 str_wc[src_chars - 1] = L'\0';-
132 wc_enabled = -
133 1-
134 ;-
135 conversion = wc_ensure_printable (str_wc);-
136 n_cols = wcswidth (str_wc, src_chars);-
137 }
never executed: end of block
0
138 }
never executed: end of block
0
139-
140-
141-
142 if (wc_enabled
wc_enabledDescription
TRUEnever evaluated
FALSEevaluated 5031 times by 4 tests
Evaluated by:
  • df
  • ls
  • numfmt
  • vdir
&& (conversion
conversionDescription
TRUEnever evaluated
FALSEnever evaluated
|| (
(n_cols > *width)Description
TRUEnever evaluated
FALSEnever evaluated
n_cols > *width)
(n_cols > *width)Description
TRUEnever evaluated
FALSEnever evaluated
))
0-5031
143 {-
144 if (conversion
conversionDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
145 {-
146-
147-
148 src_size = wcstombs (-
149 ((void *)0)-
150 , str_wc, 0) + 1;-
151 }
never executed: end of block
0
152 newstr = malloc (src_size);-
153 if (newstr ==
newstr == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
154 ((void *)0)
newstr == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
155 )-
156 {-
157 if (flags & MBA_UNIBYTE_FALLBACK
flags & MBA_UNIBYTE_FALLBACKDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
158 goto
never executed: goto mbsalign_unibyte;
mbsalign_unibyte;
never executed: goto mbsalign_unibyte;
0
159 else-
160 goto
never executed: goto mbsalign_cleanup;
mbsalign_cleanup;
never executed: goto mbsalign_cleanup;
0
161 }-
162 str_to_print = newstr;-
163 n_cols = wc_truncate (str_wc, *width);-
164 n_used_bytes = wcstombs (newstr, str_wc, src_size);-
165 }
never executed: end of block
0
166-
167mbsalign_unibyte:
code before this statement executed 5031 times by 4 tests: mbsalign_unibyte:
Executed by:
  • df
  • ls
  • numfmt
  • vdir
5031
168-
169 if (n_cols > *width
n_cols > *widthDescription
TRUEnever evaluated
FALSEevaluated 5031 times by 4 tests
Evaluated by:
  • df
  • ls
  • numfmt
  • vdir
)
0-5031
170 {-
171 n_cols = *width;-
172 n_used_bytes = n_cols;-
173 }
never executed: end of block
0
174-
175 if (*
*width > n_colsDescription
TRUEevaluated 3045 times by 4 tests
Evaluated by:
  • df
  • ls
  • numfmt
  • vdir
FALSEevaluated 1986 times by 3 tests
Evaluated by:
  • df
  • ls
  • vdir
width > n_cols
*width > n_colsDescription
TRUEevaluated 3045 times by 4 tests
Evaluated by:
  • df
  • ls
  • numfmt
  • vdir
FALSEevaluated 1986 times by 3 tests
Evaluated by:
  • df
  • ls
  • vdir
)
1986-3045
176 n_spaces = *width - n_cols;
executed 3045 times by 4 tests: n_spaces = *width - n_cols;
Executed by:
  • df
  • ls
  • numfmt
  • vdir
3045
177-
178-
179 *width = n_cols;-
180-
181 {-
182 size_t start_spaces, end_spaces;-
183-
184 switch (align)-
185 {-
186 case
executed 3927 times by 4 tests: case MBS_ALIGN_LEFT:
Executed by:
  • df
  • ls
  • numfmt
  • vdir
MBS_ALIGN_LEFT:
executed 3927 times by 4 tests: case MBS_ALIGN_LEFT:
Executed by:
  • df
  • ls
  • numfmt
  • vdir
3927
187 start_spaces = 0;-
188 end_spaces = n_spaces;-
189 break;
executed 3927 times by 4 tests: break;
Executed by:
  • df
  • ls
  • numfmt
  • vdir
3927
190 case
executed 1104 times by 2 tests: case MBS_ALIGN_RIGHT:
Executed by:
  • df
  • numfmt
MBS_ALIGN_RIGHT:
executed 1104 times by 2 tests: case MBS_ALIGN_RIGHT:
Executed by:
  • df
  • numfmt
1104
191 start_spaces = n_spaces;-
192 end_spaces = 0;-
193 break;
executed 1104 times by 2 tests: break;
Executed by:
  • df
  • numfmt
1104
194 case
never executed: case MBS_ALIGN_CENTER:
MBS_ALIGN_CENTER:
never executed: case MBS_ALIGN_CENTER:
0
195 default
never executed: default:
:
never executed: default:
0
196 start_spaces = n_spaces / 2 + n_spaces % 2;-
197 end_spaces = n_spaces / 2;-
198 break;
never executed: break;
0
199 }-
200-
201 if (flags & MBA_NO_LEFT_PAD
flags & MBA_NO_LEFT_PADDescription
TRUEnever evaluated
FALSEevaluated 5031 times by 4 tests
Evaluated by:
  • df
  • ls
  • numfmt
  • vdir
)
0-5031
202 start_spaces = 0;
never executed: start_spaces = 0;
0
203 if (flags & MBA_NO_RIGHT_PAD
flags & MBA_NO_RIGHT_PADDescription
TRUEevaluated 311 times by 1 test
Evaluated by:
  • df
FALSEevaluated 4720 times by 4 tests
Evaluated by:
  • df
  • ls
  • numfmt
  • vdir
)
311-4720
204 end_spaces = 0;
executed 311 times by 1 test: end_spaces = 0;
Executed by:
  • df
311
205-
206-
207 if (dest_size != 0
dest_size != 0Description
TRUEevaluated 5031 times by 4 tests
Evaluated by:
  • df
  • ls
  • numfmt
  • vdir
FALSEnever evaluated
)
0-5031
208 {-
209 size_t space_left;-
210 char *dest_end = dest + dest_size - 1;-
211-
212 dest = mbs_align_pad (dest, dest_end, start_spaces);-
213 space_left = dest_end - dest;-
214 dest = mempcpy (dest, str_to_print, ((n_used_bytes) < (space_left) ? (n_used_bytes) : (space_left)));-
215 mbs_align_pad (dest, dest_end, end_spaces);-
216 }
executed 5031 times by 4 tests: end of block
Executed by:
  • df
  • ls
  • numfmt
  • vdir
5031
217-
218-
219 ret = n_used_bytes + ((start_spaces + end_spaces) * 1);-
220 }-
221-
222mbsalign_cleanup:
code before this statement executed 5031 times by 4 tests: mbsalign_cleanup:
Executed by:
  • df
  • ls
  • numfmt
  • vdir
5031
223-
224 free (str_wc);-
225 free (newstr);-
226-
227 return
executed 5031 times by 4 tests: return ret;
Executed by:
  • df
  • ls
  • numfmt
  • vdir
ret;
executed 5031 times by 4 tests: return ret;
Executed by:
  • df
  • ls
  • numfmt
  • vdir
5031
228}-
229-
230-
231-
232-
233-
234char *-
235ambsalign (const char *src, size_t *width, mbs_align_t align, int flags)-
236{-
237 size_t orig_width = *width;-
238 size_t size = *width;-
239 size_t req = size;-
240 char *buf = -
241 ((void *)0)-
242 ;-
243-
244 while (req >= size
req >= sizeDescription
TRUEevaluated 1688 times by 1 test
Evaluated by:
  • df
FALSEevaluated 1688 times by 1 test
Evaluated by:
  • df
)
1688
245 {-
246 char *nbuf;-
247 size = req + 1;-
248 nbuf = realloc (buf, size);-
249 if (nbuf ==
nbuf == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1688 times by 1 test
Evaluated by:
  • df
0-1688
250 ((void *)0)
nbuf == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1688 times by 1 test
Evaluated by:
  • df
0-1688
251 )-
252 {-
253 free (buf);-
254 buf = -
255 ((void *)0)-
256 ;-
257 break;
never executed: break;
0
258 }-
259 buf = nbuf;-
260 *width = orig_width;-
261 req = mbsalign (src, buf, size, width, align, flags);-
262 if (req ==
req == (184467...73709551615UL)Description
TRUEnever evaluated
FALSEevaluated 1688 times by 1 test
Evaluated by:
  • df
0-1688
263 (18446744073709551615UL)
req == (184467...73709551615UL)Description
TRUEnever evaluated
FALSEevaluated 1688 times by 1 test
Evaluated by:
  • df
0-1688
264 )-
265 {-
266 free (buf);-
267 buf = -
268 ((void *)0)-
269 ;-
270 break;
never executed: break;
0
271 }-
272 }
executed 1688 times by 1 test: end of block
Executed by:
  • df
1688
273-
274 return
executed 1688 times by 1 test: return buf;
Executed by:
  • df
buf;
executed 1688 times by 1 test: return buf;
Executed by:
  • df
1688
275}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.1.2