public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-1143] analyzer: associate -Wanalyzer-double-fclose with CWE-1341 Date: Thu, 16 Jun 2022 21:28:12 +0000 (GMT) [thread overview] Message-ID: <20220616212812.15BAC38582AE@sourceware.org> (raw) https://gcc.gnu.org/g:065d191893234c1b2e4554fd78ba339d9b7d03e9 commit r13-1143-g065d191893234c1b2e4554fd78ba339d9b7d03e9 Author: David Malcolm <dmalcolm@redhat.com> Date: Thu Jun 16 17:27:08 2022 -0400 analyzer: associate -Wanalyzer-double-fclose with CWE-1341 gcc/analyzer/ChangeLog: * sm-file.cc (double_fclose::emit): Associate the warning with CWE-1341 ("Multiple Releases of Same Resource or Handle"). gcc/testsuite/ChangeLog: * gcc.dg/analyzer/file-1.c (test_1): Verify that double-fclose is associated with CWE-1341. Signed-off-by: David Malcolm <dmalcolm@redhat.com> Diff: --- gcc/analyzer/sm-file.cc | 9 ++++++--- gcc/testsuite/gcc.dg/analyzer/file-1.c | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/gcc/analyzer/sm-file.cc b/gcc/analyzer/sm-file.cc index 8514af19766..f6cb29c7806 100644 --- a/gcc/analyzer/sm-file.cc +++ b/gcc/analyzer/sm-file.cc @@ -178,9 +178,12 @@ public: bool emit (rich_location *rich_loc) final override { - return warning_at (rich_loc, get_controlling_option (), - "double %<fclose%> of FILE %qE", - m_arg); + diagnostic_metadata m; + /* CWE-1341: Multiple Releases of Same Resource or Handle. */ + m.add_cwe (1341); + return warning_meta (rich_loc, m, get_controlling_option (), + "double %<fclose%> of FILE %qE", + m_arg); } label_text describe_state_change (const evdesc::state_change &change) diff --git a/gcc/testsuite/gcc.dg/analyzer/file-1.c b/gcc/testsuite/gcc.dg/analyzer/file-1.c index e8d934331fd..316cbb3d868 100644 --- a/gcc/testsuite/gcc.dg/analyzer/file-1.c +++ b/gcc/testsuite/gcc.dg/analyzer/file-1.c @@ -14,7 +14,7 @@ test_1 (const char *path) fclose (f); /* { dg-message "\\(4\\) \\.\\.\\.to here" "to here" } */ /* { dg-message "\\(5\\) first 'fclose' here" "first fclose" { target *-*-* } .-1 } */ - fclose (f); /* { dg-warning "double 'fclose' of FILE 'f'" "warning" } */ + fclose (f); /* { dg-warning "double 'fclose' of FILE 'f' \\\[CWE-1341\\\]" "warning" } */ /* { dg-message "second 'fclose' here; first 'fclose' was at \\(5\\)" "second fclose" { target *-*-* } .-1 } */ }
reply other threads:[~2022-06-16 21:28 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20220616212812.15BAC38582AE@sourceware.org \ --to=dmalcolm@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /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: linkBe 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).