OpenCoverage

randint.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/gl/lib/randint.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6struct randint_source-
7{-
8-
9 struct randread_source *source;-
10-
11-
12-
13-
14-
15-
16 randint randnum;-
17 randint randmax;-
18};-
19-
20-
21-
22struct randint_source *-
23randint_new (struct randread_source *source)-
24{-
25 struct randint_source *s = xmalloc (sizeof *s);-
26 s->source = source;-
27 s->randnum = s->randmax = 0;-
28 return
executed 640 times by 6 tests: return s;
Executed by:
  • cp
  • ln
  • mktemp
  • mv
  • shred
  • shuf
s;
executed 640 times by 6 tests: return s;
Executed by:
  • cp
  • ln
  • mktemp
  • mv
  • shred
  • shuf
640
29}-
30-
31-
32-
33-
34-
35struct randint_source *-
36randint_all_new (char const *name, size_t bytes_bound)-
37{-
38 struct randread_source *source = randread_new (name, bytes_bound);-
39 return
executed 640 times by 6 tests: return (source ? randint_new (source) : ((void *)0) );
Executed by:
  • cp
  • ln
  • mktemp
  • mv
  • shred
  • shuf
(source ? randint_new (source) :
executed 640 times by 6 tests: return (source ? randint_new (source) : ((void *)0) );
Executed by:
  • cp
  • ln
  • mktemp
  • mv
  • shred
  • shuf
640
40 ((void *)0)
executed 640 times by 6 tests: return (source ? randint_new (source) : ((void *)0) );
Executed by:
  • cp
  • ln
  • mktemp
  • mv
  • shred
  • shuf
640
41 );
executed 640 times by 6 tests: return (source ? randint_new (source) : ((void *)0) );
Executed by:
  • cp
  • ln
  • mktemp
  • mv
  • shred
  • shuf
640
42}-
43-
44-
45-
46struct randread_source *-
47randint_get_source (struct randint_source const *s)-
48{-
49 return
executed 25 times by 1 test: return s->source;
Executed by:
  • shred
s->source;
executed 25 times by 1 test: return s->source;
Executed by:
  • shred
25
50}-
51-
52-
53-
54-
55enum { HUGE_BYTES = -
56 (18446744073709551615UL) -
57 == -
58 (0x7f * 2 + 1) -
59 };-
60-
61-
62static inline randint shift_left (randint x)-
63{-
64 return
executed 19431 times by 6 tests: return HUGE_BYTES ? 0 : x << 8;
Executed by:
  • cp
  • ln
  • mktemp
  • mv
  • shred
  • shuf
HUGE_BYTES ? 0 : x << 8;
executed 19431 times by 6 tests: return HUGE_BYTES ? 0 : x << 8;
Executed by:
  • cp
  • ln
  • mktemp
  • mv
  • shred
  • shuf
19431
65}-
66-
67-
68-
69-
70-
71randint-
72randint_genmax (struct randint_source *s, randint genmax)-
73{-
74 struct randread_source *source = s->source;-
75 randint randnum = s->randnum;-
76 randint randmax = s->randmax;-
77 randint choices = genmax + 1;-
78-
79 while (1)-
80 {-
81 if (randmax < genmax
randmax < genmaxDescription
TRUEevaluated 6144 times by 6 tests
Evaluated by:
  • cp
  • ln
  • mktemp
  • mv
  • shred
  • shuf
FALSEevaluated 4211 times by 6 tests
Evaluated by:
  • cp
  • ln
  • mktemp
  • mv
  • shred
  • shuf
)
4211-6144
82 {-
83-
84-
85-
86 size_t i = 0;-
87 randint rmax = randmax;-
88 unsigned char buf[sizeof randnum];-
89-
90 do-
91 {-
92 rmax = shift_left (rmax) + -
93 (0x7f * 2 + 1)-
94 ;-
95 i++;-
96 }
executed 6477 times by 6 tests: end of block
Executed by:
  • cp
  • ln
  • mktemp
  • mv
  • shred
  • shuf
6477
97 while (rmax < genmax
rmax < genmaxDescription
TRUEevaluated 333 times by 1 test
Evaluated by:
  • shuf
FALSEevaluated 6144 times by 6 tests
Evaluated by:
  • cp
  • ln
  • mktemp
  • mv
  • shred
  • shuf
);
333-6144
98-
99 randread (source, buf, i);-
100 i = 0;-
101-
102 do-
103 {-
104 randnum = shift_left (randnum) + buf[i];-
105 randmax = shift_left (randmax) + -
106 (0x7f * 2 + 1)-
107 ;-
108 i++;-
109 }
executed 6477 times by 6 tests: end of block
Executed by:
  • cp
  • ln
  • mktemp
  • mv
  • shred
  • shuf
6477
110 while (randmax < genmax
randmax < genmaxDescription
TRUEevaluated 333 times by 1 test
Evaluated by:
  • shuf
FALSEevaluated 6144 times by 6 tests
Evaluated by:
  • cp
  • ln
  • mktemp
  • mv
  • shred
  • shuf
);
333-6144
111 }
executed 6144 times by 6 tests: end of block
Executed by:
  • cp
  • ln
  • mktemp
  • mv
  • shred
  • shuf
6144
112-
113 if (randmax == genmax
randmax == genmaxDescription
TRUEevaluated 79 times by 2 tests
Evaluated by:
  • shred
  • shuf
FALSEevaluated 10276 times by 6 tests
Evaluated by:
  • cp
  • ln
  • mktemp
  • mv
  • shred
  • shuf
)
79-10276
114 {-
115 s->randnum = s->randmax = 0;-
116 return
executed 79 times by 2 tests: return randnum;
Executed by:
  • shred
  • shuf
randnum;
executed 79 times by 2 tests: return randnum;
Executed by:
  • shred
  • shuf
79
117 }-
118 else-
119 {-
120 randint excess_choices = randmax - genmax;-
121 randint unusable_choices = excess_choices % choices;-
122 randint last_usable_choice = randmax - unusable_choices;-
123 randint reduced_randnum = randnum % choices;-
124-
125 if (randnum <= last_usable_choice
randnum <= last_usable_choiceDescription
TRUEevaluated 9538 times by 6 tests
Evaluated by:
  • cp
  • ln
  • mktemp
  • mv
  • shred
  • shuf
FALSEevaluated 738 times by 5 tests
Evaluated by:
  • cp
  • ln
  • mktemp
  • mv
  • shuf
)
738-9538
126 {-
127 s->randnum = randnum / choices;-
128 s->randmax = excess_choices / choices;-
129 return
executed 9538 times by 6 tests: return reduced_randnum;
Executed by:
  • cp
  • ln
  • mktemp
  • mv
  • shred
  • shuf
reduced_randnum;
executed 9538 times by 6 tests: return reduced_randnum;
Executed by:
  • cp
  • ln
  • mktemp
  • mv
  • shred
  • shuf
9538
130 }-
131-
132-
133-
134 randnum = reduced_randnum;-
135 randmax = unusable_choices - 1;-
136 }
executed 738 times by 5 tests: end of block
Executed by:
  • cp
  • ln
  • mktemp
  • mv
  • shuf
738
137 }-
138}
never executed: end of block
0
139-
140-
141-
142void-
143randint_free (struct randint_source *s)-
144{-
145 explicit_bzero (s, sizeof *s);-
146 free (s);-
147}
executed 620 times by 5 tests: end of block
Executed by:
  • cp
  • ln
  • mktemp
  • mv
  • shred
620
148-
149-
150-
151-
152int-
153randint_all_free (struct randint_source *s)-
154{-
155 int r = randread_free (s->source);-
156 int e = -
157 (*__errno_location ())-
158 ;-
159 randint_free (s);-
160 -
161 (*__errno_location ()) -
162 = e;-
163 return
executed 620 times by 5 tests: return r;
Executed by:
  • cp
  • ln
  • mktemp
  • mv
  • shred
r;
executed 620 times by 5 tests: return r;
Executed by:
  • cp
  • ln
  • mktemp
  • mv
  • shred
620
164}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.1.2