From 7f865577a6224fbbb5f5ca52574b62ea8ac9bf51 Mon Sep 17 00:00:00 2001 From: Lasse Collin Date: Sat, 27 Apr 2024 14:56:16 +0300 Subject: [PATCH] Tests: test_index: Make it clear that my_alloc() has no integer overflows liblzma guarantees that the product of the allocation size arguments will fit in size_t. Putting the pre-increment in the if-statement was clearly wrong although in practice it didn't matter here as the function is called only a couple of times. --- tests/test_index.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_index.c b/tests/test_index.c index f6369221..5eed4931 100644 --- a/tests/test_index.c +++ b/tests/test_index.c @@ -1282,10 +1282,13 @@ my_alloc(void *opaque, size_t a, size_t b) { (void)opaque; + assert_true(SIZE_MAX / a >= b); + static unsigned count = 0; - if (++count > 2) + if (count >= 2) return NULL; + ++count; return malloc(a * b); }