From 112fa18bfa293629ccb90fbd952aa6e61398da80 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 25 Nov 2022 09:31:28 -0500 Subject: Constrain benchmark parameters to reasonable limits --- benchmark/tree_bench.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'benchmark') diff --git a/benchmark/tree_bench.c b/benchmark/tree_bench.c index 7754857..b9e230e 100644 --- a/benchmark/tree_bench.c +++ b/benchmark/tree_bench.c @@ -22,6 +22,14 @@ ZIX_RESTORE_WARNINGS #include #include +#ifndef MIN +# define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#endif + +#ifndef MAX +# define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#endif + static int int_cmp(const void* a, const void* b, const void* ZIX_UNUSED(user_data)) { @@ -267,8 +275,8 @@ main(int argc, char** argv) return 1; } - const size_t min_n = strtoul(argv[1], NULL, 10); - const size_t max_n = strtoul(argv[2], NULL, 10); + const size_t min_n = MAX(2U, MIN(1U << 29U, strtoul(argv[1], NULL, 10))); + const size_t max_n = MAX(4U, MIN(1U << 30U, strtoul(argv[2], NULL, 10))); fprintf(stderr, "Benchmarking %zu .. %zu elements\n", min_n, max_n); -- cgit v1.2.1