This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH, testsuite] Prevent warnings due to dummy malloc calls.
- From: Doug Evans <dje at google dot com>
- To: lgustavo at codesourcery dot com
- Cc: "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>
- Date: Tue, 26 Nov 2013 13:12:47 -0800
- Subject: Re: [PATCH, testsuite] Prevent warnings due to dummy malloc calls.
- Authentication-results: sourceware.org; auth=none
- References: <5294F42D dot 6020007 at codesourcery dot com>
On Tue, Nov 26, 2013 at 11:19 AM, Luis Machado
<lgustavo@codesourcery.com> 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 */
}