Skip to content

Commit f4b7df8

Browse files
committed
tests: fix undefined behaviour
Ensure that we do not attempt a divide-by-zero. Adjust the loop count accordingly.
1 parent 698d085 commit f4b7df8

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

tests/dispatch_group.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ test_group_notify2(long cycle, dispatch_group_t tested)
143143
dispatch_group_async(group, q, ^{
144144
// Seems to trigger a little more reliably with some work being
145145
// done in this block
146+
assert(cycle && "cycle must be non-zero");
146147
eh = (float)sin(M_1_PI / cycle);
147148
});
148149
}
@@ -171,9 +172,9 @@ test_group_notify(void *ctxt __attribute__((unused)))
171172
dispatch_group_t tested = dispatch_group_create();
172173
test_ptr_notnull("dispatch_group_create", tested);
173174
long i;
174-
for (i = 0; i < LOOP_COUNT; i++) {
175-
if (!((i+1) % (LOOP_COUNT/10))) {
176-
fprintf(stderr, "#%ld\n", i+1);
175+
for (i = 1; i <= LOOP_COUNT; i++) {
176+
if (!(i % (LOOP_COUNT/10))) {
177+
fprintf(stderr, "#%ld\n", i);
177178
}
178179
dispatch_group_enter(tested);
179180
test_group_notify2(i, tested);
@@ -182,7 +183,7 @@ test_group_notify(void *ctxt __attribute__((unused)))
182183
break;
183184
}
184185
}
185-
test_long("dispatch_group_notify", i, LOOP_COUNT);
186+
test_long("dispatch_group_notify", i - 1, LOOP_COUNT);
186187
test_stop();
187188
}
188189

0 commit comments

Comments
 (0)