public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-1144] analyzer: associate -Wanalyzer-va-list-exhausted with CWE-685
@ 2022-06-16 21:34 David Malcolm
0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2022-06-16 21:34 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:f443024bca7c1ac988eb7c05e639b017347ee714
commit r13-1144-gf443024bca7c1ac988eb7c05e639b017347ee714
Author: David Malcolm <dmalcolm@redhat.com>
Date: Thu Jun 16 17:33:40 2022 -0400
analyzer: associate -Wanalyzer-va-list-exhausted with CWE-685
gcc/analyzer/ChangeLog:
* varargs.cc: Include "diagnostic-metadata.h".
(va_list_exhausted::emit): Associate the warning with
CWE-685 ("Function Call With Incorrect Number of Arguments").
gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/stdarg-1.c
(__analyzer_called_by_test_not_enough_args): Verify that
-Wanalyzer-va-list-exhausted is associated with CWE-685.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diff:
---
gcc/analyzer/varargs.cc | 10 +++++++---
gcc/testsuite/gcc.dg/analyzer/stdarg-1.c | 2 +-
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/gcc/analyzer/varargs.cc b/gcc/analyzer/varargs.cc
index 846a0b1e3ff..3baba7988c1 100644
--- a/gcc/analyzer/varargs.cc
+++ b/gcc/analyzer/varargs.cc
@@ -50,6 +50,7 @@ along with GCC; see the file COPYING3. If not see
#include "sbitmap.h"
#include "analyzer/diagnostic-manager.h"
#include "analyzer/exploded-graph.h"
+#include "diagnostic-metadata.h"
#if ENABLE_ANALYZER
@@ -903,9 +904,12 @@ public:
bool emit (rich_location *rich_loc) final override
{
auto_diagnostic_group d;
- bool warned = warning_at (rich_loc, get_controlling_option (),
- "%qE has no more arguments (%i consumed)",
- m_va_list_tree, get_num_consumed ());
+ diagnostic_metadata m;
+ /* CWE-685: Function Call With Incorrect Number of Arguments. */
+ m.add_cwe (685);
+ bool warned = warning_meta (rich_loc, m, get_controlling_option (),
+ "%qE has no more arguments (%i consumed)",
+ m_va_list_tree, get_num_consumed ());
return warned;
}
diff --git a/gcc/testsuite/gcc.dg/analyzer/stdarg-1.c b/gcc/testsuite/gcc.dg/analyzer/stdarg-1.c
index 295f0efb74d..41935f74cc3 100644
--- a/gcc/testsuite/gcc.dg/analyzer/stdarg-1.c
+++ b/gcc/testsuite/gcc.dg/analyzer/stdarg-1.c
@@ -76,7 +76,7 @@ __analyzer_called_by_test_not_enough_args (int placeholder, ...)
s = __builtin_va_arg (ap, char *);
__analyzer_eval (s[0] == 'f'); /* { dg-warning "TRUE" } */
- i = __builtin_va_arg (ap, int); /* { dg-warning "'ap' has no more arguments \\(1 consumed\\)" } */
+ i = __builtin_va_arg (ap, int); /* { dg-warning "'ap' has no more arguments \\(1 consumed\\) \\\[CWE-685\\\]" } */
__builtin_va_end (ap);
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-16 21:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-16 21:34 [gcc r13-1144] analyzer: associate -Wanalyzer-va-list-exhausted with CWE-685 David Malcolm
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).