From patchwork Mon Dec 16 19:17:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Castanho X-Patchwork-Id: 36897 Received: (qmail 114421 invoked by alias); 16 Dec 2019 19:17:49 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 114412 invoked by uid 89); 16 Dec 2019 19:17:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-27.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy=worrying, HContent-Transfer-Encoding:8bit X-HELO: mx0a-001b2d01.pphosted.com From: Matheus Castanho To: libc-alpha@sourceware.org Subject: [RFC][PATCH] malloc: Fix test for malloc_usable_size Date: Mon, 16 Dec 2019 16:17:42 -0300 Message-Id: <20191216191742.1035-1-msc@linux.ibm.com> MIME-Version: 1.0 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(-) diff --git a/malloc/tst-malloc-usable.c b/malloc/tst-malloc-usable.c index aa572fa06a..767f4ac6ef 100644 --- a/malloc/tst-malloc-usable.c +++ b/malloc/tst-malloc-usable.c @@ -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; }