From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 80D6E3858D37; Thu, 20 Apr 2023 13:33:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 80D6E3858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681997626; bh=IoFME1u/lOcaWrDn6GYit7IpNPcEt6C27dqqaAkwpAw=; h=From:To:Subject:Date:From; b=wYv7Aofl+7ISVnAAFnePt1NKlSCGp+w+wEuDHKF39cDJJVZlH36ZOLenrYI7xV3E7 frnuoK0C5N5OEETuI+xg0ZxQxar/ahoBXtrPTO/q6qT4bVOteeH8YvtZSmewtx6Z9h s5b3gyjzWSoP01mTt3zsIqd9lfDikNiIG3a/l3XQ= From: "vanyacpp at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug analyzer/109570] New: detect fclose on unopened or NULL files Date: Thu, 20 Apr 2023 13:33:46 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new 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: vanyacpp at gmail dot com 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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 Bug ID: 109570 Summary: detect fclose on unopened or NULL files Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: analyzer Assignee: dmalcolm at gcc dot gnu.org Reporter: vanyacpp at gmail dot com Target Milestone: --- While cleaning up one not particularly well written program I noticed this = code fragment: FILE* file =3D fopen(...); if (!file) { fclose(file); return false; } Passing NULL to fclose is undefined behavior. Perhaps -fanalyzer could warn about code like this?=