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.

(cherry picked from commit 7f865577a6)
This commit is contained in:
Lasse Collin 2024-04-27 14:56:16 +03:00
parent 189251f5d2
commit 24dd20ca1d
1 changed files with 4 additions and 1 deletions

View File

@ -1282,10 +1282,13 @@ my_alloc(void *opaque, size_t a, size_t b)
{ {
(void)opaque; (void)opaque;
assert_true(SIZE_MAX / a >= b);
static unsigned count = 0; static unsigned count = 0;
if (++count > 2) if (count >= 2)
return NULL; return NULL;
++count;
return malloc(a * b); return malloc(a * b);
} }