[RFC] malloc: Fix test for malloc_usable_size
Commit Message
Hi,
We have seen some tests on recent builds on ppc64le failing with
the following:
---=== ./malloc/tst-malloc-usable-tunables.out ===---
malloc_usable_size: expected 7 but got 24
FAIL: malloc/tst-malloc-usable-tunables.c
After taking a look at the contents of that test, the check failing
actually comes from tst-malloc-usable.c, which tests if the value
returned by malloc_usable_size() is different than the number of bytes
requested for allocation by a previous call to malloc. However, per
malloc/malloc.c:
malloc_usable_size(void* p);
Returns the number of bytes you can actually use in
an allocated chunk, which may be more than you requested (although
often not) due to alignment and minimum size constraints.
You can use this many bytes without worrying about
overwriting other allocated objects.
Based on that, is there any special reason why the comparison on
tst-malloc-usable.c is a != instead of a <, since the size of the
allocated chunk may be greater than what was requested?
Matheus Castanho
---
Currently malloc/tst-malloc-usable.c fails if the return value of
malloc_usable_size() is different than the number of bytes requested
for allocation by a previous call to malloc(), which may not always
be the case. This commit changes that check to avoid false positives
when running this test.
---
malloc/tst-malloc-usable.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
@@ -34,9 +34,9 @@ do_test (void)
}
usable_size = malloc_usable_size (p);
- if (usable_size != 7)
+ if (usable_size < 7)
{
- printf ("malloc_usable_size: expected 7 but got %zu\n", usable_size);
+ printf ("malloc_usable_size: expected at least 7 but got %zu\n", usable_size);
return 1;
}