Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/coreutils/src/gl/lib/randread.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | - | |||||||||||||||||||
4 | - | |||||||||||||||||||
5 | - | |||||||||||||||||||
6 | struct randread_source | - | ||||||||||||||||||
7 | { | - | ||||||||||||||||||
8 | - | |||||||||||||||||||
9 | - | |||||||||||||||||||
10 | FILE *source; | - | ||||||||||||||||||
11 | - | |||||||||||||||||||
12 | - | |||||||||||||||||||
13 | - | |||||||||||||||||||
14 | - | |||||||||||||||||||
15 | - | |||||||||||||||||||
16 | - | |||||||||||||||||||
17 | void (*handler) (void const *); | - | ||||||||||||||||||
18 | void const *handler_arg; | - | ||||||||||||||||||
19 | - | |||||||||||||||||||
20 | - | |||||||||||||||||||
21 | - | |||||||||||||||||||
22 | - | |||||||||||||||||||
23 | union | - | ||||||||||||||||||
24 | { | - | ||||||||||||||||||
25 | - | |||||||||||||||||||
26 | char c[(2 * ((1 << 8) * sizeof (isaac_word)))]; | - | ||||||||||||||||||
27 | - | |||||||||||||||||||
28 | - | |||||||||||||||||||
29 | struct isaac | - | ||||||||||||||||||
30 | { | - | ||||||||||||||||||
31 | - | |||||||||||||||||||
32 | size_t buffered; | - | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | - | |||||||||||||||||||
35 | struct isaac_state state; | - | ||||||||||||||||||
36 | - | |||||||||||||||||||
37 | - | |||||||||||||||||||
38 | union | - | ||||||||||||||||||
39 | { | - | ||||||||||||||||||
40 | isaac_word w[(1 << 8)]; | - | ||||||||||||||||||
41 | unsigned char b[((1 << 8) * sizeof (isaac_word))]; | - | ||||||||||||||||||
42 | } data; | - | ||||||||||||||||||
43 | } isaac; | - | ||||||||||||||||||
44 | } buf; | - | ||||||||||||||||||
45 | }; | - | ||||||||||||||||||
46 | - | |||||||||||||||||||
47 | - | |||||||||||||||||||
48 | - | |||||||||||||||||||
49 | - | |||||||||||||||||||
50 | static void __attribute__ ((__noreturn__)) | - | ||||||||||||||||||
51 | randread_error (void const *file_name) | - | ||||||||||||||||||
52 | { | - | ||||||||||||||||||
53 | if (file_name
| 0 | ||||||||||||||||||
54 | error (exit_failure, never executed: error (exit_failure, (*__errno_location ()) , (*__errno_location ()) == 0 ? dcgettext (((void *)0), "%s: end of file" , 5) : dcgettext (((void *)0), "%s: read error" , 5) , quote (file_name)); | 0 | ||||||||||||||||||
55 | (*__errno_location ()) never executed: error (exit_failure, (*__errno_location ()) , (*__errno_location ()) == 0 ? dcgettext (((void *)0), "%s: end of file" , 5) : dcgettext (((void *)0), "%s: read error" , 5) , quote (file_name)); | 0 | ||||||||||||||||||
56 | , never executed: error (exit_failure, (*__errno_location ()) , (*__errno_location ()) == 0 ? dcgettext (((void *)0), "%s: end of file" , 5) : dcgettext (((void *)0), "%s: read error" , 5) , quote (file_name)); | 0 | ||||||||||||||||||
57 | never executed: error (exit_failure, (*__errno_location ()) , (*__errno_location ()) == 0 ? dcgettext (((void *)0), "%s: end of file" , 5) : dcgettext (((void *)0), "%s: read error" , 5) , quote (file_name)); | 0 | ||||||||||||||||||
58 | (*__errno_location ()) never executed: error (exit_failure, (*__errno_location ()) , (*__errno_location ()) == 0 ? dcgettext (((void *)0), "%s: end of file" , 5) : dcgettext (((void *)0), "%s: read error" , 5) , quote (file_name)); | 0 | ||||||||||||||||||
59 | == 0 ? never executed: error (exit_failure, (*__errno_location ()) , (*__errno_location ()) == 0 ? dcgettext (((void *)0), "%s: end of file" , 5) : dcgettext (((void *)0), "%s: read error" , 5) , quote (file_name)); | 0 | ||||||||||||||||||
60 | dcgettext (((void *)0), never executed: error (exit_failure, (*__errno_location ()) , (*__errno_location ()) == 0 ? dcgettext (((void *)0), "%s: end of file" , 5) : dcgettext (((void *)0), "%s: read error" , 5) , quote (file_name)); | 0 | ||||||||||||||||||
61 | "%s: end of file" never executed: error (exit_failure, (*__errno_location ()) , (*__errno_location ()) == 0 ? dcgettext (((void *)0), "%s: end of file" , 5) : dcgettext (((void *)0), "%s: read error" , 5) , quote (file_name)); | 0 | ||||||||||||||||||
62 | , 5) never executed: error (exit_failure, (*__errno_location ()) , (*__errno_location ()) == 0 ? dcgettext (((void *)0), "%s: end of file" , 5) : dcgettext (((void *)0), "%s: read error" , 5) , quote (file_name)); | 0 | ||||||||||||||||||
63 | : never executed: error (exit_failure, (*__errno_location ()) , (*__errno_location ()) == 0 ? dcgettext (((void *)0), "%s: end of file" , 5) : dcgettext (((void *)0), "%s: read error" , 5) , quote (file_name)); | 0 | ||||||||||||||||||
64 | dcgettext (((void *)0), never executed: error (exit_failure, (*__errno_location ()) , (*__errno_location ()) == 0 ? dcgettext (((void *)0), "%s: end of file" , 5) : dcgettext (((void *)0), "%s: read error" , 5) , quote (file_name)); | 0 | ||||||||||||||||||
65 | "%s: read error" never executed: error (exit_failure, (*__errno_location ()) , (*__errno_location ()) == 0 ? dcgettext (((void *)0), "%s: end of file" , 5) : dcgettext (((void *)0), "%s: read error" , 5) , quote (file_name)); | 0 | ||||||||||||||||||
66 | , 5) never executed: error (exit_failure, (*__errno_location ()) , (*__errno_location ()) == 0 ? dcgettext (((void *)0), "%s: end of file" , 5) : dcgettext (((void *)0), "%s: read error" , 5) , quote (file_name)); | 0 | ||||||||||||||||||
67 | , never executed: error (exit_failure, (*__errno_location ()) , (*__errno_location ()) == 0 ? dcgettext (((void *)0), "%s: end of file" , 5) : dcgettext (((void *)0), "%s: read error" , 5) , quote (file_name)); | 0 | ||||||||||||||||||
68 | quote (file_name)); never executed: error (exit_failure, (*__errno_location ()) , (*__errno_location ()) == 0 ? dcgettext (((void *)0), "%s: end of file" , 5) : dcgettext (((void *)0), "%s: read error" , 5) , quote (file_name)); | 0 | ||||||||||||||||||
69 | abort (); never executed: abort (); | 0 | ||||||||||||||||||
70 | } | - | ||||||||||||||||||
71 | - | |||||||||||||||||||
72 | - | |||||||||||||||||||
73 | - | |||||||||||||||||||
74 | - | |||||||||||||||||||
75 | static struct randread_source * | - | ||||||||||||||||||
76 | simple_new (FILE *source, void const *handler_arg) | - | ||||||||||||||||||
77 | { | - | ||||||||||||||||||
78 | struct randread_source *s = xmalloc (sizeof *s); | - | ||||||||||||||||||
79 | s->source = source; | - | ||||||||||||||||||
80 | s->handler = randread_error; | - | ||||||||||||||||||
81 | s->handler_arg = handler_arg; | - | ||||||||||||||||||
82 | return executed 655 times by 7 tests: s;return s; Executed by:
executed 655 times by 7 tests: return s; Executed by:
| 655 | ||||||||||||||||||
83 | } | - | ||||||||||||||||||
84 | - | |||||||||||||||||||
85 | - | |||||||||||||||||||
86 | - | |||||||||||||||||||
87 | - | |||||||||||||||||||
88 | - | |||||||||||||||||||
89 | static void | - | ||||||||||||||||||
90 | get_nonce (void *buffer, size_t bufsize, size_t bytes_bound) | - | ||||||||||||||||||
91 | { | - | ||||||||||||||||||
92 | char *buf = buffer; | - | ||||||||||||||||||
93 | ssize_t seeded = 0; | - | ||||||||||||||||||
94 | - | |||||||||||||||||||
95 | - | |||||||||||||||||||
96 | int fd = open ("/dev/urandom", | - | ||||||||||||||||||
97 | 00 | - | ||||||||||||||||||
98 | | | - | ||||||||||||||||||
99 | 0 | - | ||||||||||||||||||
100 | ); | - | ||||||||||||||||||
101 | if (0 <= fd
| 0-649 | ||||||||||||||||||
102 | { | - | ||||||||||||||||||
103 | seeded = read (fd, buf, ((bufsize) < (bytes_bound) ? (bufsize) : (bytes_bound))); | - | ||||||||||||||||||
104 | if (seeded < 0
| 0-649 | ||||||||||||||||||
105 | seeded = 0; never executed: seeded = 0; | 0 | ||||||||||||||||||
106 | close (fd); | - | ||||||||||||||||||
107 | } executed 649 times by 7 tests: end of block Executed by:
| 649 | ||||||||||||||||||
108 | if (seeded < bufsize
| 0-618 | ||||||||||||||||||
109 | ((void *)0) | - | ||||||||||||||||||
110 | ); memcpy (buf + seeded, &v, nbytes); seeded += nbytes; } executed 618 times by 6 tests: ;end of block Executed by:
| 618 | ||||||||||||||||||
111 | if (seeded < bufsize
executed 618 times by 6 tests: ;end of block Executed by:
| 0-618 | ||||||||||||||||||
112 | if (seeded < bufsize
executed 618 times by 6 tests: ;end of block Executed by:
| 0-618 | ||||||||||||||||||
113 | if (seeded < bufsize
executed 618 times by 6 tests: ;end of block Executed by:
| 0-618 | ||||||||||||||||||
114 | if (seeded < bufsize
executed 618 times by 6 tests: ;end of block Executed by:
| 0-618 | ||||||||||||||||||
115 | - | |||||||||||||||||||
116 | - | |||||||||||||||||||
117 | - | |||||||||||||||||||
118 | - | |||||||||||||||||||
119 | - | |||||||||||||||||||
120 | - | |||||||||||||||||||
121 | - | |||||||||||||||||||
122 | } executed 649 times by 7 tests: end of block Executed by:
| 649 | ||||||||||||||||||
123 | struct randread_source * | - | ||||||||||||||||||
124 | randread_new (char const *name, size_t bytes_bound) | - | ||||||||||||||||||
125 | { | - | ||||||||||||||||||
126 | if (bytes_bound == 0
| 4-651 | ||||||||||||||||||
127 | return executed 4 times by 1 test: simple_new (return simple_new ( ((void *)0) , ((void *)0) ); Executed by:
executed 4 times by 1 test: return simple_new ( ((void *)0) , ((void *)0) ); Executed by:
| 4 | ||||||||||||||||||
128 | ((void *)0) executed 4 times by 1 test: return simple_new ( ((void *)0) , ((void *)0) ); Executed by:
| 4 | ||||||||||||||||||
129 | , executed 4 times by 1 test: return simple_new ( ((void *)0) , ((void *)0) ); Executed by:
| 4 | ||||||||||||||||||
130 | ((void *)0) executed 4 times by 1 test: return simple_new ( ((void *)0) , ((void *)0) ); Executed by:
| 4 | ||||||||||||||||||
131 | ); executed 4 times by 1 test: return simple_new ( ((void *)0) , ((void *)0) ); Executed by:
| 4 | ||||||||||||||||||
132 | else | - | ||||||||||||||||||
133 | { | - | ||||||||||||||||||
134 | FILE *source = | - | ||||||||||||||||||
135 | ((void *)0) | - | ||||||||||||||||||
136 | ; | - | ||||||||||||||||||
137 | struct randread_source *s; | - | ||||||||||||||||||
138 | - | |||||||||||||||||||
139 | if (name
| 2-649 | ||||||||||||||||||
140 | if (! (source = fopen_safer (name, "rb"))
| 0-2 | ||||||||||||||||||
141 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
142 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
143 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
144 | - | |||||||||||||||||||
145 | s = simple_new (source, name); | - | ||||||||||||||||||
146 | - | |||||||||||||||||||
147 | if (source
| 2-649 | ||||||||||||||||||
148 | setvbuf (source, s->buf.c, executed 2 times by 2 tests: setvbuf (source, s->buf.c, 0 , ((sizeof s->buf.c) < (bytes_bound) ? (sizeof s->buf.c) : (bytes_bound))); Executed by:
| 2 | ||||||||||||||||||
149 | 0 executed 2 times by 2 tests: setvbuf (source, s->buf.c, 0 , ((sizeof s->buf.c) < (bytes_bound) ? (sizeof s->buf.c) : (bytes_bound))); Executed by:
| 2 | ||||||||||||||||||
150 | , ((sizeof s->buf.c) < (bytes_bound) ? (sizeof s->buf.c) : (bytes_bound))); executed 2 times by 2 tests: setvbuf (source, s->buf.c, 0 , ((sizeof s->buf.c) < (bytes_bound) ? (sizeof s->buf.c) : (bytes_bound))); Executed by:
| 2 | ||||||||||||||||||
151 | else | - | ||||||||||||||||||
152 | { | - | ||||||||||||||||||
153 | s->buf.isaac.buffered = 0; | - | ||||||||||||||||||
154 | get_nonce (s->buf.isaac.state.m, sizeof s->buf.isaac.state.m, | - | ||||||||||||||||||
155 | bytes_bound); | - | ||||||||||||||||||
156 | isaac_seed (&s->buf.isaac.state); | - | ||||||||||||||||||
157 | } executed 649 times by 7 tests: end of block Executed by:
| 649 | ||||||||||||||||||
158 | - | |||||||||||||||||||
159 | return executed 651 times by 7 tests: s;return s; Executed by:
executed 651 times by 7 tests: return s; Executed by:
| 651 | ||||||||||||||||||
160 | } | - | ||||||||||||||||||
161 | } | - | ||||||||||||||||||
162 | void | - | ||||||||||||||||||
163 | randread_set_handler (struct randread_source *s, void (*handler) (void const *)) | - | ||||||||||||||||||
164 | { | - | ||||||||||||||||||
165 | s->handler = handler; | - | ||||||||||||||||||
166 | } never executed: end of block | 0 | ||||||||||||||||||
167 | - | |||||||||||||||||||
168 | void | - | ||||||||||||||||||
169 | randread_set_handler_arg (struct randread_source *s, void const *handler_arg) | - | ||||||||||||||||||
170 | { | - | ||||||||||||||||||
171 | s->handler_arg = handler_arg; | - | ||||||||||||||||||
172 | } never executed: end of block | 0 | ||||||||||||||||||
173 | - | |||||||||||||||||||
174 | - | |||||||||||||||||||
175 | - | |||||||||||||||||||
176 | - | |||||||||||||||||||
177 | - | |||||||||||||||||||
178 | static void | - | ||||||||||||||||||
179 | readsource (struct randread_source *s, unsigned char *p, size_t size) | - | ||||||||||||||||||
180 | { | - | ||||||||||||||||||
181 | while ( | - | ||||||||||||||||||
182 | 1 | - | ||||||||||||||||||
183 | ) | - | ||||||||||||||||||
184 | { | - | ||||||||||||||||||
185 | size_t inbytes = fread_unlocked (p,sizeof *p,size,s->source); | - | ||||||||||||||||||
186 | int fread_errno = | - | ||||||||||||||||||
187 | (*__errno_location ()) | - | ||||||||||||||||||
188 | ; | - | ||||||||||||||||||
189 | p += inbytes; | - | ||||||||||||||||||
190 | size -= inbytes; | - | ||||||||||||||||||
191 | if (size == 0
| 0-18 | ||||||||||||||||||
192 | break; executed 18 times by 2 tests: break; Executed by:
| 18 | ||||||||||||||||||
193 | - | |||||||||||||||||||
194 | (*__errno_location ()) | - | ||||||||||||||||||
195 | = (ferror_unlocked (s->source) ? fread_errno : 0); | - | ||||||||||||||||||
196 | s->handler (s->handler_arg); | - | ||||||||||||||||||
197 | } never executed: end of block | 0 | ||||||||||||||||||
198 | } executed 18 times by 2 tests: end of block Executed by:
| 18 | ||||||||||||||||||
199 | - | |||||||||||||||||||
200 | - | |||||||||||||||||||
201 | - | |||||||||||||||||||
202 | - | |||||||||||||||||||
203 | - | |||||||||||||||||||
204 | static void | - | ||||||||||||||||||
205 | readisaac (struct isaac *isaac, void *p, size_t size) | - | ||||||||||||||||||
206 | { | - | ||||||||||||||||||
207 | size_t inbytes = isaac->buffered; | - | ||||||||||||||||||
208 | - | |||||||||||||||||||
209 | while ( | - | ||||||||||||||||||
210 | 1 | - | ||||||||||||||||||
211 | ) | - | ||||||||||||||||||
212 | { | - | ||||||||||||||||||
213 | char *char_p = p; | - | ||||||||||||||||||
214 | - | |||||||||||||||||||
215 | if (size <= inbytes
| 685-6236 | ||||||||||||||||||
216 | { | - | ||||||||||||||||||
217 | memcpy (p, isaac->data.b + ((1 << 8) * sizeof (isaac_word)) - inbytes, size); | - | ||||||||||||||||||
218 | isaac->buffered = inbytes - size; | - | ||||||||||||||||||
219 | return; executed 6236 times by 7 tests: return; Executed by:
| 6236 | ||||||||||||||||||
220 | } | - | ||||||||||||||||||
221 | - | |||||||||||||||||||
222 | memcpy (p, isaac->data.b + ((1 << 8) * sizeof (isaac_word)) - inbytes, inbytes); | - | ||||||||||||||||||
223 | p = char_p + inbytes; | - | ||||||||||||||||||
224 | size -= inbytes; | - | ||||||||||||||||||
225 | - | |||||||||||||||||||
226 | - | |||||||||||||||||||
227 | - | |||||||||||||||||||
228 | if ( | - | ||||||||||||||||||
229 | 1 | - | ||||||||||||||||||
230 | ) | - | ||||||||||||||||||
231 | { | - | ||||||||||||||||||
232 | isaac_word *wp = p; | - | ||||||||||||||||||
233 | while (((
| 669-1023 | ||||||||||||||||||
234 | { | - | ||||||||||||||||||
235 | isaac_refill (&isaac->state, wp); | - | ||||||||||||||||||
236 | wp += (1 << 8); | - | ||||||||||||||||||
237 | size -= ((1 << 8) * sizeof (isaac_word)); | - | ||||||||||||||||||
238 | if (size == 0
| 16-1007 | ||||||||||||||||||
239 | { | - | ||||||||||||||||||
240 | isaac->buffered = 0; | - | ||||||||||||||||||
241 | return; executed 16 times by 1 test: return; Executed by:
| 16 | ||||||||||||||||||
242 | } | - | ||||||||||||||||||
243 | } executed 1007 times by 1 test: end of block Executed by:
| 1007 | ||||||||||||||||||
244 | p = wp; | - | ||||||||||||||||||
245 | } executed 669 times by 7 tests: end of block Executed by:
| 669 | ||||||||||||||||||
246 | - | |||||||||||||||||||
247 | isaac_refill (&isaac->state, isaac->data.w); | - | ||||||||||||||||||
248 | inbytes = ((1 << 8) * sizeof (isaac_word)); | - | ||||||||||||||||||
249 | } executed 669 times by 7 tests: end of block Executed by:
| 669 | ||||||||||||||||||
250 | } never executed: end of block | 0 | ||||||||||||||||||
251 | - | |||||||||||||||||||
252 | - | |||||||||||||||||||
253 | - | |||||||||||||||||||
254 | - | |||||||||||||||||||
255 | - | |||||||||||||||||||
256 | void | - | ||||||||||||||||||
257 | randread (struct randread_source *s, void *buf, size_t size) | - | ||||||||||||||||||
258 | { | - | ||||||||||||||||||
259 | if (s->source
| 18-6252 | ||||||||||||||||||
260 | readsource (s, buf, size); executed 18 times by 2 tests: readsource (s, buf, size); Executed by:
| 18 | ||||||||||||||||||
261 | else | - | ||||||||||||||||||
262 | readisaac (&s->buf.isaac, buf, size); executed 6252 times by 7 tests: readisaac (&s->buf.isaac, buf, size); Executed by:
| 6252 | ||||||||||||||||||
263 | } | - | ||||||||||||||||||
264 | - | |||||||||||||||||||
265 | - | |||||||||||||||||||
266 | - | |||||||||||||||||||
267 | - | |||||||||||||||||||
268 | - | |||||||||||||||||||
269 | - | |||||||||||||||||||
270 | - | |||||||||||||||||||
271 | int | - | ||||||||||||||||||
272 | randread_free (struct randread_source *s) | - | ||||||||||||||||||
273 | { | - | ||||||||||||||||||
274 | FILE *source = s->source; | - | ||||||||||||||||||
275 | explicit_bzero (s, sizeof *s); | - | ||||||||||||||||||
276 | free (s); | - | ||||||||||||||||||
277 | return executed 635 times by 6 tests: (source ? return (source ? rpl_fclose (source) : 0); Executed by:
executed 635 times by 6 tests: return (source ? rpl_fclose (source) : 0); Executed by:
| 635 | ||||||||||||||||||
278 | rpl_fclose executed 635 times by 6 tests: return (source ? rpl_fclose (source) : 0); Executed by:
| 635 | ||||||||||||||||||
279 | (source) : 0); executed 635 times by 6 tests: return (source ? rpl_fclose (source) : 0); Executed by:
| 635 | ||||||||||||||||||
280 | } | - | ||||||||||||||||||
Switch to Source code | Preprocessed file |