mirror of https://git.tukaani.org/xz.git
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:
parent
189251f5d2
commit
24dd20ca1d
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue