]> gcc.gnu.org Git - gcc.git/commitdiff
analyzer: associate -Wanalyzer-double-fclose with CWE-1341
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 16 Jun 2022 21:27:08 +0000 (17:27 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Thu, 16 Jun 2022 21:27:08 +0000 (17:27 -0400)
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>
gcc/analyzer/sm-file.cc
gcc/testsuite/gcc.dg/analyzer/file-1.c

index 8514af197667a26ec36ec9af3a2e43031b677580..f6cb29c7806c0c5d2f0a17169d34f57e1aea3f61 100644 (file)
@@ -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)
index e8d934331fd473383335482e8c94af34cecf2a1e..316cbb3d8680b358bbfda33230b89b368c0beb47 100644 (file)
@@ -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 } */
 }
 
This page took 0.080993 seconds and 5 git commands to generate.