From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5B73A3858C41; Wed, 17 May 2023 15:14:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5B73A3858C41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684336455; bh=DnjhFS78i5Is0Vn5PWEg6/ssVqcT73loWj8WuAOvnFE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Wr1CC+UiQ1aOjN5rvB8mGkW4fiG+V8iPS+Xf5eALupCMuf8osTzKqLTv16asiVSPm tZU1F7hm7+QFkpjfpUb3a1v3IKYeeYat4x7VM7Cs9cn92Oa+4DpLqtGHJfxPN6y86x bmBX/uVmQEPmxebTeiHVBZoWqMThntvtL/IeVeyA= From: "xry111 at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug analyzer/109570] detect fclose on unopened or NULL files Date: Wed, 17 May 2023 15:14:15 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: analyzer X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: xry111 at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: dmalcolm 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109570 --- Comment #6 from Xi Ruoyao --- (In reply to Christophe Lyon from comment #5) > Not sure how to update/fix the testcases though? > Since they get the declaration of fclose from stdio.h, we'd need to make > dg-error conditional to the glibc version in use, which seems unpractical. >=20 > Should we instead remove #include and provide suitable > declarations in the testcase? I guess we need to change return ferror (f) || fclose (f) !=3D 0; to return !f || ferror (f) || fclose (f) !=3D 0; Because "failing to check if the file is opened successfully" is definitely= a bug, and these tests are intended not to raise warnings for a bug-free prog= ram. BTW ferror(f) segfaults as well when f is NULL, so IMO we should mark it nonnull in Glibc as well.=