From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 897753858430; Sat, 13 Nov 2021 18:34:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 897753858430 From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug bootstrap/80047] fixincludes/fixincl.c: PVS-Studio: Improper Release of Memory Before Removing Last Reference (CWE-401) Date: Sat, 13 Nov 2021 18:34:16 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: bootstrap X-Bugzilla-Version: 7.0.1 X-Bugzilla-Keywords: build, patch X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: msebor at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Nov 2021 18:34:16 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D80047 --- Comment #8 from CVS Commits --- The master branch has been updated by Xi Ruoyao : https://gcc.gnu.org/g:04c5a91d068c4ca2f09c2bc206fce00db9d1790b commit r12-5234-g04c5a91d068c4ca2f09c2bc206fce00db9d1790b Author: Xi Ruoyao Date: Tue Nov 9 21:40:04 2021 +0800 fixincludes: simplify handling for access() failure [PR21283, PR80047] POSIX says: On some implementations, if buf is a null pointer, getcwd() may obt= ain size bytes of memory using malloc(). In this case, the pointer retu= rned by getcwd() may be used as the argument in a subsequent call to fre= e(). Invoking getcwd() with buf as a null pointer is not recommended in conforming applications. This produces an error building GCC with --enable-werror-always: ../../../fixincludes/fixincl.c: In function =C3=A2process=C3=A2: ../../../fixincludes/fixincl.c:1356:7: error: argument 1 is null but the corresponding size argument 2 value is 4096 [-Werror=3Dnonnull] It's suggested by POSIX to call getcwd() with progressively larger buffers until it does not give an [ERANGE] error. However, it's highly unlikely that this error-handling route is ever used. So we can simplify it instead of writting too much code. We give up to use getcwd(), because `make` will output a `Leaving directory ...` mess= age containing the path to cwd when we call abort(). fixincludes/ChangeLog: PR other/21823 PR bootstrap/80047 * fixincl.c (process): Simplify the handling for highly unlikely access() failure, to avoid using non-standard extensions.=