From patchwork Thu Oct 3 12:26:07 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Newton X-Patchwork-Id: 20785 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qe0-f70.google.com (mail-qe0-f70.google.com [209.85.128.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CB62525CAB for ; Thu, 3 Oct 2013 12:26:11 +0000 (UTC) Received: by mail-qe0-f70.google.com with SMTP id b4sf4930543qen.9 for ; Thu, 03 Oct 2013 05:26:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:message-id:date:from:user-agent :mime-version:to:cc:subject:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe:content-type :content-transfer-encoding; bh=PCUAbrMDylzO61K7l8ib7YLa4ae8mK/tNTO2jutEpbk=; b=cPdCAaye9kZ1PIGNakoRZkgfv62lHdkWf3zZC/mHVy28tOFekFpwJZmzCl/Y743Ijm j4q0s2nWbyN6IxTaRdalbZwvWKyRe9XFNAZkOpVQMOsf6h3/bSO66/Hw5dfo4yC2pMq2 XiH8xlUvCUc5B8tB5uiOmY4OvZE50ByX2zPnnmOm38mtHUtc8EU0MpNDQhh3rQcD+L2g 392BnsWCz6mlVKlaPySAYVuJnnrfLTwO8kXV+v2cgvzIhA8VZrsixUm+8Wk9Uyjrh4GC lfvFP1dpEHHyByt1HSr/KPXABWbtXF0jRH+gGqSo8KPDRA2f7myIgaEzudknUOIZY/d5 qGWQ== X-Received: by 10.236.122.234 with SMTP id t70mr6741443yhh.23.1380803171671; Thu, 03 Oct 2013 05:26:11 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.39.104 with SMTP id o8ls1005980qek.38.gmail; Thu, 03 Oct 2013 05:26:11 -0700 (PDT) X-Received: by 10.52.161.231 with SMTP id xv7mr6046962vdb.1.1380803171561; Thu, 03 Oct 2013 05:26:11 -0700 (PDT) Received: from mail-vb0-f53.google.com (mail-vb0-f53.google.com [209.85.212.53]) by mx.google.com with ESMTPS id ug9si1656347vcb.107.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 03 Oct 2013 05:26:11 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.53 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.53; Received: by mail-vb0-f53.google.com with SMTP id i3so1529419vbh.12 for ; Thu, 03 Oct 2013 05:26:11 -0700 (PDT) X-Gm-Message-State: ALoCoQnY/oeFiEE7VtygF4DTLtNmRA0LyXFp46xkLNPfYbrFl81bWKGCPgIO+0zj3DHlNV2vCQmk X-Received: by 10.52.98.131 with SMTP id ei3mr6046786vdb.4.1380803171471; Thu, 03 Oct 2013 05:26:11 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp174075vcz; Thu, 3 Oct 2013 05:26:10 -0700 (PDT) X-Received: by 10.180.39.212 with SMTP id r20mr2253706wik.13.1380803170454; Thu, 03 Oct 2013 05:26:10 -0700 (PDT) Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com [209.85.212.181]) by mx.google.com with ESMTPS id w8si2881998wiy.3.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 03 Oct 2013 05:26:10 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.181 is neither permitted nor denied by best guess record for domain of will.newton@linaro.org) client-ip=209.85.212.181; Received: by mail-wi0-f181.google.com with SMTP id ex4so2483610wid.8 for ; Thu, 03 Oct 2013 05:26:09 -0700 (PDT) X-Received: by 10.180.20.77 with SMTP id l13mr2300620wie.40.1380803169880; Thu, 03 Oct 2013 05:26:09 -0700 (PDT) Received: from localhost.localdomain (cpc6-seac21-2-0-cust453.7-2.cable.virginmedia.com. [82.1.113.198]) by mx.google.com with ESMTPSA id iz19sm13429838wic.9.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 03 Oct 2013 05:26:09 -0700 (PDT) Message-ID: <524D625F.4080208@linaro.org> Date: Thu, 03 Oct 2013 13:26:07 +0100 From: Will Newton User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130805 Thunderbird/17.0.8 MIME-Version: 1.0 To: libc-alpha@sourceware.org CC: patches@linaro.org Subject: [PATCH] malloc/tst-valloc.c: Tidy up code. X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: will.newton@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.53 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Add some comments and call free on all potentially allocated pointers. Also remove duplicate check for NULL pointer. ChangeLog: 2013-10-03 Will Newton * malloc/tst-valloc.c: Add comments. (do_test): Add comments and call free on all potentially allocated pointers. Remove duplicate check for NULL pointer. Add space after cast. --- malloc/tst-valloc.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/malloc/tst-valloc.c b/malloc/tst-valloc.c index 3648f2f..7676e66 100644 --- a/malloc/tst-valloc.c +++ b/malloc/tst-valloc.c @@ -1,4 +1,5 @@ -/* Copyright (C) 2013 Free Software Foundation, Inc. +/* Test for valloc. + Copyright (C) 2013 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -40,6 +41,8 @@ do_test (void) errno = 0; + /* An attempt to allocate a huge value should return NULL and set + errno to ENOMEM. */ p = valloc (-1); save = errno; @@ -50,8 +53,11 @@ do_test (void) if (p == NULL && save != ENOMEM) merror ("valloc (-1) errno is not set correctly"); + free (p); + errno = 0; + /* Test to expose integer overflow in malloc internals from BZ #15856. */ p = valloc (-pagesize); save = errno; @@ -62,6 +68,10 @@ do_test (void) if (p == NULL && save != ENOMEM) merror ("valloc (-pagesize) errno is not set correctly"); + free (p); + + /* A zero-sized allocation should succeed with glibc, returning a + non-NULL value. */ p = valloc (0); if (p == NULL) @@ -69,15 +79,13 @@ do_test (void) free (p); + /* Check the alignment of the returned pointer is correct. */ p = valloc (32); if (p == NULL) merror ("valloc (32) failed."); - ptrval = (unsigned long)p; - - if (p == NULL) - merror ("valloc (32) failed."); + ptrval = (unsigned long) p; if ((ptrval & (pagesize - 1)) != 0) merror ("returned pointer is not page aligned.");