From 6bc45c0f6e14df97bb4869d8202cf5d020c97fa8 Mon Sep 17 00:00:00 2001 From: David Rheinsberg Date: Mon, 15 Apr 2024 13:16:04 +0200 Subject: [PATCH] test: avoid division by zero 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 Signed-off-by: David Rheinsberg --- src/test-basic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test-basic.c b/src/test-basic.c index 7a7ce3b..6fc63e6 100644 --- a/src/test-basic.c +++ b/src/test-basic.c @@ -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) {