From patchwork Thu Oct 3 12:25:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Newton X-Patchwork-Id: 20784 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f197.google.com (mail-vc0-f197.google.com [209.85.220.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5224D25CAB for ; Thu, 3 Oct 2013 12:25:29 +0000 (UTC) Received: by mail-vc0-f197.google.com with SMTP id gd11sf3189624vcb.8 for ; Thu, 03 Oct 2013 05:25:28 -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=j/J2n8nnJCNlZecs+fxSxJYMRjyLeSjqJpnCcnQ4QVk=; b=LPFEdWWhf+U2oPknhL1f8MZf7yQcQ8liTLoqy2u5psegdZDD5NMfwHVB0YP+SzVH7u s+VrIXVo2eOETbKg4eJdoCogMNujpH1kjqEpqKE7uwvekszS2aHPqVw7QYi21e7Uzqt0 +qqyDw09Dihp1HZDK4Lv7AgpV7Pg0mFDLp+mJwqwuNc9D8N5Pk7b7tFTp7trcz8xt6+g m/UQ48VnVFMHr8HTQFjAvNbmfqxMZju1Ilb+t4tm1Q6FADEQ5qdGvvoiTNXEafv7NXsZ RcDLCscRmRuKm+c1jzbLoOhNmXp91wEoE+ulf5WtsY1LlGvgECAF8VTi7Yw2l8ACg7ly Z7CQ== X-Received: by 10.236.94.205 with SMTP id n53mr7718820yhf.44.1380803128706; Thu, 03 Oct 2013 05:25:28 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.29.229 with SMTP id n5ls858687qeh.73.gmail; Thu, 03 Oct 2013 05:25:28 -0700 (PDT) X-Received: by 10.52.33.44 with SMTP id o12mr6052334vdi.7.1380803128577; Thu, 03 Oct 2013 05:25:28 -0700 (PDT) Received: from mail-vb0-f45.google.com (mail-vb0-f45.google.com [209.85.212.45]) by mx.google.com with ESMTPS id dp7si1665555ved.35.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 03 Oct 2013 05:25:28 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.45 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.45; Received: by mail-vb0-f45.google.com with SMTP id e15so1518630vbg.32 for ; Thu, 03 Oct 2013 05:25:28 -0700 (PDT) X-Gm-Message-State: ALoCoQkJuudzja61ABXrAsTlc/mwKYpmxmVQmCFOSmBZyBYMEmL0WetDL5xGkxIRAwN67imASqV/ X-Received: by 10.58.168.205 with SMTP id zy13mr7206635veb.19.1380803128482; Thu, 03 Oct 2013 05:25:28 -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 u4csp174020vcz; Thu, 3 Oct 2013 05:25:27 -0700 (PDT) X-Received: by 10.15.98.9 with SMTP id bi9mr2690168eeb.67.1380803127360; Thu, 03 Oct 2013 05:25:27 -0700 (PDT) Received: from mail-ee0-f49.google.com (mail-ee0-f49.google.com [74.125.83.49]) by mx.google.com with ESMTPS id q8si5755077eem.30.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 03 Oct 2013 05:25:27 -0700 (PDT) Received-SPF: neutral (google.com: 74.125.83.49 is neither permitted nor denied by best guess record for domain of will.newton@linaro.org) client-ip=74.125.83.49; Received: by mail-ee0-f49.google.com with SMTP id d41so1059425eek.36 for ; Thu, 03 Oct 2013 05:25:26 -0700 (PDT) X-Received: by 10.14.5.3 with SMTP id 3mr3932784eek.49.1380803126631; Thu, 03 Oct 2013 05:25:26 -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 r48sm15189533eev.14.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 03 Oct 2013 05:25:25 -0700 (PDT) Message-ID: <524D6234.7050206@linaro.org> Date: Thu, 03 Oct 2013 13:25:24 +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-pvalloc.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.45 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-pvalloc.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-pvalloc.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/malloc/tst-pvalloc.c b/malloc/tst-pvalloc.c index 1126672..0227091 100644 --- a/malloc/tst-pvalloc.c +++ b/malloc/tst-pvalloc.c @@ -1,4 +1,5 @@ -/* Copyright (C) 2013 Free Software Foundation, Inc. +/* Test for pvalloc. + 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 = pvalloc (-1); save = errno; @@ -50,8 +53,11 @@ do_test (void) if (p == NULL && save != ENOMEM) merror ("pvalloc (-1) errno is not set correctly"); + free (p); + errno = 0; + /* Test to expose integer overflow in malloc internals from BZ #15855. */ p = pvalloc (-pagesize); save = errno; @@ -62,6 +68,10 @@ do_test (void) if (p == NULL && save != ENOMEM) merror ("pvalloc (-pagesize) errno is not set correctly"); + free (p); + + /* A zero-sized allocation should succeed with glibc, returning a + non-NULL value. */ p = pvalloc (0); if (p == NULL) @@ -69,15 +79,13 @@ do_test (void) free (p); + /* Check the alignment of the returned pointer is correct. */ p = pvalloc (32); if (p == NULL) merror ("pvalloc (32) failed."); - ptrval = (unsigned long)p; - - if (p == NULL) - merror ("pvalloc (32) failed."); + ptrval = (unsigned long) p; if ((ptrval & (pagesize - 1)) != 0) merror ("returned pointer is not page aligned.");