From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18800 invoked by alias); 26 Nov 2013 19:19:37 -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 18757 invoked by uid 89); 26 Nov 2013 19:19:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.8 required=5.0 tests=AWL,BAYES_40,RDNS_NONE,URIBL_BLOCKED autolearn=no version=3.3.2 X-HELO: relay1.mentorg.com Received: from Unknown (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 26 Nov 2013 19:19:35 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1VlOAJ-0006AD-OP from Luis_Gustavo@mentor.com for gdb-patches@sourceware.org; Tue, 26 Nov 2013 11:19:19 -0800 Received: from NA1-MAIL.mgc.mentorg.com ([147.34.98.181]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Tue, 26 Nov 2013 11:19:19 -0800 Received: from [172.30.2.203] ([172.30.2.203]) by NA1-MAIL.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 26 Nov 2013 11:19:19 -0800 Message-ID: <5294F42D.6020007@codesourcery.com> Date: Tue, 26 Nov 2013 21:32:00 -0000 From: Luis Machado Reply-To: lgustavo@codesourcery.com User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 To: "'gdb-patches@sourceware.org'" Subject: [PATCH, testsuite] Prevent warnings due to dummy malloc calls. Content-Type: multipart/mixed; boundary="------------020505030406050508030600" X-IsSubscribed: yes X-SW-Source: 2013-11/txt/msg00824.txt.bz2 This is a multi-part message in MIME format. --------------020505030406050508030600 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 630 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? --------------020505030406050508030600 Content-Type: text/x-patch; name="malloc.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="malloc.diff" Content-length: 2749 2013-11-26 Luis Machado gdb/testsuite/ * gdb.base/callfuncs.c (main): Assign malloc's return value and free it afterwards. * gdb.base/charset-malloc.c (malloc_stub): Likewise. * gdb.base/printcmds.c (main): Likewise. * gdb.base/randomize.c (main): Free "p". * gdb.base/setvar.c (dummy): Assign malloc's return value and free it afterwards. diff --git a/gdb/testsuite/gdb.base/callfuncs.c b/gdb/testsuite/gdb.base/callfuncs.c index 0d76ee9..3872f5c 100644 --- a/gdb/testsuite/gdb.base/callfuncs.c +++ b/gdb/testsuite/gdb.base/callfuncs.c @@ -652,9 +652,13 @@ voidfunc (void) int main () { - malloc(1); + void *p = malloc (1); t_double_values(double_val1, double_val2); t_structs_c(struct_val1); + + if (p != NULL) + free (p); + return 0 ; } diff --git a/gdb/testsuite/gdb.base/charset-malloc.c b/gdb/testsuite/gdb.base/charset-malloc.c index 58242a2..54a9bd6 100644 --- a/gdb/testsuite/gdb.base/charset-malloc.c +++ b/gdb/testsuite/gdb.base/charset-malloc.c @@ -31,5 +31,8 @@ malloc_stub (void) { /* charset.exp wants to allocate memory for constants. So make sure malloc gets linked into the program. */ - malloc (1); + void *p = malloc (1); + + if (p != NULL) + free (p); } diff --git a/gdb/testsuite/gdb.base/printcmds.c b/gdb/testsuite/gdb.base/printcmds.c index d80c13d..806f421 100644 --- a/gdb/testsuite/gdb.base/printcmds.c +++ b/gdb/testsuite/gdb.base/printcmds.c @@ -218,10 +218,13 @@ char invalid_RRR[] = "aaaaaaaaaaaaaaaaaaaa" int main () { - malloc(1); + void *p = malloc (1); /* Prevent AIX linker from removing variables. */ return ctable1[0] + ctable2[0] + int1dim[0] + int2dim[0][0] + int3dim[0][0][0] + int4dim[0][0][0][0] + teststring[0] + *parrays -> array1 + a1[0] + a2[0]; + + if (p != NULL) + free (p); } 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 */ } diff --git a/gdb/testsuite/gdb.base/setvar.c b/gdb/testsuite/gdb.base/setvar.c index 3a80b22..0022dc0 100644 --- a/gdb/testsuite/gdb.base/setvar.c +++ b/gdb/testsuite/gdb.base/setvar.c @@ -204,7 +204,7 @@ dummy () { /* setvar.exp wants to allocate memory for constants. So make sure malloc gets linked into the program. */ - malloc (1); + void *p = malloc (1); /* Some linkers (e.g. on AIX) remove unreferenced variables, so make sure to reference them. */ @@ -278,4 +278,7 @@ dummy () sef.field = s1; uef.field = u1; #endif + + if (p != NULL) + free (p); } --------------020505030406050508030600--