public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Thomas Schwinge <thomas@codesourcery.com>
To: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Cc: <gcc-patches@gcc.gnu.org>, <fortran@gcc.gnu.org>
Subject: Re: [PATCH][stage1] Remove conditionals around free()
Date: Wed, 8 Mar 2023 22:56:36 +0100	[thread overview]
Message-ID: <87ttyurjor.fsf@dirichlet.schwinge.homeip.net> (raw)
In-Reply-To: <20230301222856.12300c64@nbbrfq>

Hi Bernhard!

On 2023-03-01T22:28:56+0100, Bernhard Reutner-Fischer via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
> // POSIX: free(NULL) is perfectly valid
> // quote: If ptr is a null pointer, no action shall occur.
> @ rule1 @
> expression e;
> @@
>
> - if (e != NULL)
> -  { free(e); }
> + free (e);

Nice, Coccinelle/spatch!  (Another very interesting tool that I so far
had no chance to actually use.)

> # find ./ \( -name "*.[ch]" -o -name "*.cpp" \) -a \( ! -path "./gcc/testsuite/*" -a ! -path "./gcc/contrib/*" \) -exec spatch --sp-file ~/coccinelle/free-without-if-null.0.cocci --in-place

Also include '*.cc' if you'd like to find some more in 'gcc/' (and
possibly elsewhere, too) than just the following lonely one.  ;-)

> --- a/gcc/ada/rtinit.c
> +++ b/gcc/ada/rtinit.c
> @@ -481,8 +481,7 @@ __gnat_runtime_initialize (int install_handler)
>
>                    FindClose (hDir);
>
> -                  if (dir != NULL)
> -                    free (dir);
> +                  free (dir);


Grüße
 Thomas
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

      parent reply	other threads:[~2023-03-08 21:56 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-01 21:28 Bernhard Reutner-Fischer
2023-03-01 21:58 ` Bernhard Reutner-Fischer
2023-03-01 22:54   ` Bernhard Reutner-Fischer
2023-03-01 22:59 ` Andrew Pinski
2023-03-01 23:52   ` Bernhard Reutner-Fischer
2023-03-02  0:39     ` Andrew Pinski
2023-03-02  0:07 ` Steve Kargl
2023-03-02  1:23   ` Jerry D
2023-03-03 23:11     ` Bernhard Reutner-Fischer
2023-03-03 23:32       ` Iain Sandoe
2023-03-04  3:14         ` Jerry D
2023-03-24  6:30           ` NightStrike
2023-05-08  6:01   ` Bernhard Reutner-Fischer
2023-03-02  3:23 ` Ian Lance Taylor
2023-03-04 10:15 ` Janne Blomqvist
2023-03-22  7:21   ` Eric Gallager
2023-03-08 21:56 ` Thomas Schwinge [this message]

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=87ttyurjor.fsf@dirichlet.schwinge.homeip.net \
    --to=thomas@codesourcery.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=rep.dot.nop@gmail.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).