From: Doug Evans <dje@google.com>
To: lgustavo@codesourcery.com
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: [PATCH, testsuite] Prevent warnings due to dummy malloc calls.
Date: Tue, 26 Nov 2013 21:50:00 -0000 [thread overview]
Message-ID: <CADPb22Q6StsbEnoGbdWx3wGAZp43rKMvV5PwJuXS3MUL11p72g@mail.gmail.com> (raw)
In-Reply-To: <5294F42D.6020007@codesourcery.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 */
}
next prev parent reply other threads:[~2013-11-26 21:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-26 21:32 Luis Machado
2013-11-26 21:50 ` Doug Evans [this message]
2013-11-26 21:50 ` Luis Machado
2013-11-27 14:44 ` Luis Machado
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CADPb22Q6StsbEnoGbdWx3wGAZp43rKMvV5PwJuXS3MUL11p72g@mail.gmail.com \
--to=dje@google.com \
--cc=gdb-patches@sourceware.org \
--cc=lgustavo@codesourcery.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox