From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19985 invoked by alias); 26 Nov 2013 21:14:00 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 19971 invoked by uid 89); 26 Nov 2013 21:13:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL,BAYES_40,RDNS_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no version=3.3.2 X-HELO: mail-vb0-f50.google.com Received: from Unknown (HELO mail-vb0-f50.google.com) (209.85.212.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 26 Nov 2013 21:12:55 +0000 Received: by mail-vb0-f50.google.com with SMTP id 10so4253935vbe.37 for ; Tue, 26 Nov 2013 13:12:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=00oyc15Xxe0gSeYdp9T7uaIeOxiftgkNEvCYH16jlZM=; b=kyNVFNFTcarq63DTugGUU6zqU8Z2uCGhOCTQyNB1ZMn0TKQxStmwz4w66S8FjWMp0V nc1FpSAPsIo1XZ/PwbXnK1bAfZetLKU/xpy7WtONvPLtZ/lhjQ41OKGjXlogfjdfwXQN UwVACZ/AL6q5Z4+jhILe9e9pGfiPOWYnPKDttHsb6hWzxVrB77q2w6ubaGEq7ztsX8a2 q50fSWm1tiYoWKbil1gXLtERIWNi3NtuRqsXPnQPsgUys/RKq1ADxZ+uz03v8dhnWXal geSFxcY9Ax1WAqLsgMfbw9dK3Uyvo1mBnABNsXazhLmTohQbZCcIu5UkJdaGwlSioaqX UWaQ== X-Gm-Message-State: ALoCoQm5lF5XMu6L7E+ihZi/3FjyJQWTkxN3MYIi/eQPR/ysgleVPIkG27bOaq4+y73Dk8Cv5fZtc97FO17Pw4YNVqjix5wVbPWmXmZ3Z1tEAuIj+S3k3t/OlLtQ8iv2yiEZMJrzcWEc0MJubEHlvczRgOZhlOg0vUwfGYlTR2mug0CK6ENaRq/FhR60hIKMm+SKeBmLGx0d7wLg/b2LB85UfQ4BeqfmBA== MIME-Version: 1.0 X-Received: by 10.52.244.15 with SMTP id xc15mr373056vdc.52.1385500367293; Tue, 26 Nov 2013 13:12:47 -0800 (PST) Received: by 10.52.163.52 with HTTP; Tue, 26 Nov 2013 13:12:47 -0800 (PST) In-Reply-To: <5294F42D.6020007@codesourcery.com> References: <5294F42D.6020007@codesourcery.com> Date: Tue, 26 Nov 2013 21:50:00 -0000 Message-ID: Subject: Re: [PATCH, testsuite] Prevent warnings due to dummy malloc calls. From: Doug Evans To: lgustavo@codesourcery.com Cc: "gdb-patches@sourceware.org" Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes X-SW-Source: 2013-11/txt/msg00825.txt.bz2 On Tue, Nov 26, 2013 at 11:19 AM, Luis Machado wrote: > Hi, > > When running GDB's testsuite with libraries/compilers that are more > restrictive in terms of warnings, i've found that some tests were failing > due to malloc being called but not having its return value assigned to any > variables, leading to this warning: > > warning: ignoring return value of 'malloc', declared with attribute > warn_unused_result [-Wunused-result] > > The following patch adjusts those testcases to silence the warnings by (1) > assigning malloc's return value and (2) freeing that pointer later on. > > In the case of gdb.base/randomize.c, we're missing a free call, which leads > to an unused variable warning. > > Ok? Coping with these kinds of warnings is a really slippery slope, the testsuite is just not ready IMO. OTOH, I don't mind changes like this particular one. One nit: Please change all occurrences of this: + if (p != NULL) + free (p); to this + free (p); It's simpler and equally correct. The randomize.c case is a bit odd, printing p after it's freed. Maybe just add a comment explaining why things are the way they are? diff --git a/gdb/testsuite/gdb.base/randomize.c b/gdb/testsuite/gdb.base/randomize.c index 6a65663..127a4c7 100644 --- a/gdb/testsuite/gdb.base/randomize.c +++ b/gdb/testsuite/gdb.base/randomize.c @@ -24,5 +24,8 @@ int main() p = malloc (1); + if (p != NULL) + free (p); + return 0; /* print p */ }