analyzer: associate -Wanalyzer-va-arg-type-mismatch with CWE-686
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 16 Jun 2022 21:35:16 +0000 (17:35 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Thu, 16 Jun 2022 21:35:16 +0000 (17:35 -0400)
gcc/analyzer/ChangeLog:
* varargs.cc (va_arg_type_mismatch::emit): Associate the warning
with CWE-686 ("Function Call With Incorrect Argument Type").

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/stdarg-1.c
(__analyzer_called_by_test_type_mismatch_1): Verify that
-Wanalyzer-va-arg-type-mismatch is associated with CWE-686.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/analyzer/varargs.cc
gcc/testsuite/gcc.dg/analyzer/stdarg-1.c

index 3baba79..c92a56d 100644 (file)
@@ -857,12 +857,15 @@ public:
   bool emit (rich_location *rich_loc) final override
   {
     auto_diagnostic_group d;
+    diagnostic_metadata m;
+    /* "CWE-686: Function Call With Incorrect Argument Type".  */
+    m.add_cwe (686);
     bool warned
-      = warning_at (rich_loc, get_controlling_option (),
-                   "%<va_arg%> expected %qT but received %qT"
-                   " for variadic argument %i of %qE",
-                   m_expected_type, m_actual_type,
-                   get_variadic_index_for_diagnostic (), m_va_list_tree);
+      = warning_meta (rich_loc, m, get_controlling_option (),
+                     "%<va_arg%> expected %qT but received %qT"
+                     " for variadic argument %i of %qE",
+                     m_expected_type, m_actual_type,
+                     get_variadic_index_for_diagnostic (), m_va_list_tree);
     return warned;
   }
 
index 41935f7..f23d28c 100644 (file)
@@ -195,7 +195,7 @@ __analyzer_called_by_test_type_mismatch_1 (int placeholder, ...)
   __builtin_va_list ap;
   __builtin_va_start (ap, placeholder);
 
-  i = __builtin_va_arg (ap, int); /* { dg-warning "'va_arg' expected 'int' but received '\[^\n\r\]*' for variadic argument 1 of 'ap'" } */
+  i = __builtin_va_arg (ap, int); /* { dg-warning "'va_arg' expected 'int' but received '\[^\n\r\]*' for variadic argument 1 of 'ap' \\\[CWE-686\\\]" } */
 
   __builtin_va_end (ap);
 }