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 '