Skip to content

Commit

Permalink
test: avoid division by zero
Browse files Browse the repository at this point in the history
If the test is invoked with and empty argument array, we would use
0 (`argc`) as divisior in a test-division. Avoid this and use a divisor
that is never 0.

This also fixes a test-failure in a later `builtin_constant_p()` test
that righfully assumes that `non_constant_expr` cannot be 0 given that
it was used as divisor before.

Reported-by: ms178 <m.seyfarth@gmail.com>
Signed-off-by: David Rheinsberg <david@readahead.eu>
  • Loading branch information
dvdhrm committed Apr 15, 2024
1 parent 1f8d194 commit 6bc45c0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/test-basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ static void test_basic_gnuc(int non_constant_expr) {
c_assert(foo == 11);

c_assert(__builtin_constant_p(c_div_round_up(1, 5)));
c_assert(!__builtin_constant_p(c_div_round_up(1, non_constant_expr)));
c_assert(!__builtin_constant_p(c_div_round_up(8, 1 + !non_constant_expr)));

/* alternative calculation is [(x + y - 1) / y], but it may overflow */
for (i = 0; i <= 0xffff; ++i) {
Expand Down

0 comments on commit 6bc45c0

Please sign in to comment.