From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id BE0AF3858D33; Wed, 8 Mar 2023 21:56:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BE0AF3858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.98,244,1673942400"; d="scan'208";a="100874076" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 08 Mar 2023 13:56:46 -0800 IronPort-SDR: u9qEyZE84WzQpQ5fevj3JnBNc1QFnIjDW2ebdaEd8+yHCalD7Z7KsLFhmEjyS27XlUpYNA61bA l++4M30Qap4CFVvBRW+2S5KVpH9y4MNqPBGIdpxVGUWW3pIZETzhJw3HhAfY2Ym8fZk2EuBBrg OaoMdSZdMVgD49m3wOpFci8sJ+Lxn20Zz6PdhmODUso3NYinXAfHO95m+iiDgCyq2UXUctPTrR bZUCZ5Wxj3Is+LuXPWAriqS+Ot9q0kRPMeXoL6rnilQQAM/C/qEJqaodlGtxcCzPX3tcGfmpUy AX8= From: Thomas Schwinge To: Bernhard Reutner-Fischer CC: , Subject: Re: [PATCH][stage1] Remove conditionals around free() In-Reply-To: <20230301222856.12300c64@nbbrfq> References: <20230301222856.12300c64@nbbrfq> User-Agent: Notmuch/0.29.1+93~g67ed7df (https://notmuchmail.org) Emacs/27.1 (i686-pc-linux-gnu) Date: Wed, 8 Mar 2023 22:56:36 +0100 Message-ID: <87ttyurjor.fsf@dirichlet.schwinge.homeip.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-13.mgc.mentorg.com (139.181.222.13) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-5.9 required=5.0 tests=BAYES_00,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi Bernhard! On 2023-03-01T22:28:56+0100, Bernhard Reutner-Fischer via Gcc-patches wrote: > // POSIX: free(NULL) is perfectly valid > // quote: If ptr is a null pointer, no action shall occur. > @ rule1 @ > expression e; > @@ > > - if (e !=3D 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/test= suite/*" -a ! -path "./gcc/contrib/*" \) -exec spatch --sp-file ~/coccinell= e/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 !=3D NULL) > - free (dir); > + free (dir); Gr=C3=BC=C3=9Fe Thomas ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstra=C3=9Fe 201= , 80634 M=C3=BCnchen; Gesellschaft mit beschr=C3=A4nkter Haftung; Gesch=C3= =A4ftsf=C3=BChrer: Thomas Heurung, Frank Th=C3=BCrauf; Sitz der Gesellschaf= t: M=C3=BCnchen; Registergericht M=C3=BCnchen, HRB 106955