From bbd27b4ff9a2c1cfb142603861bbe0b41a3c3818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 11 Dec 2025 20:37:29 +0100 Subject: [PATCH] Fix #14323 (Addons; Add optional "cwe" attribute) --- lib/cppcheck.cpp | 3 +++ test/cli/premium_test.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 9aa7ec9d6b0..c47d133236a 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1593,6 +1593,9 @@ void CppCheck::executeAddons(const std::vector& files, const std::s } errmsg.file0 = file0; + if (obj.count("cwe")>0) + errmsg.cwe = CWE(obj["cwe"].get()); + if (obj.count("hash")>0) errmsg.hash = obj["hash"].get(); diff --git a/test/cli/premium_test.py b/test/cli/premium_test.py index 45121819e87..1bb01260b42 100644 --- a/test/cli/premium_test.py +++ b/test/cli/premium_test.py @@ -166,6 +166,23 @@ def test_help(tmpdir): assert 'cppchecksolutions.com' in stdout, stdout # check for premium help link +def test_cwe(tmpdir): + # Trac 14323 - addon warnings with cwe + test_file = os.path.join(tmpdir, 'test.c') + addon_file = os.path.join(tmpdir, 'premiumaddon.py') + + with open(test_file, 'wt') as f: + f.write('void foo();\n') + + args = [f"--addon={addon_file}", '--xml', test_file] + + with open(addon_file, 'wt') as f: + f.write('print(\'{"addon":"a","column":1,"errorId":"id","extra":"","file":"test.c","cwe":123,"linenr":1,"message":"bug","severity":"error"}\')') + + _, _, stderr = cppcheck(args) + assert '