Skip to content

Commit 575de99

Browse files
authored
Fix #14323 (Addons; Add optional "cwe" attribute) (danmar#8026)
1 parent 40cf3c3 commit 575de99

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/cppcheck.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,6 +1602,9 @@ void CppCheck::executeAddons(const std::vector<std::string>& files, const std::s
16021602
}
16031603
errmsg.file0 = file0;
16041604

1605+
if (obj.count("cwe")>0)
1606+
errmsg.cwe = CWE(obj["cwe"].get<std::int64_t>());
1607+
16051608
if (obj.count("hash")>0)
16061609
errmsg.hash = obj["hash"].get<std::int64_t>();
16071610

test/cli/premium_test.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,23 @@ def test_help(tmpdir):
166166
assert 'cppchecksolutions.com' in stdout, stdout # check for premium help link
167167

168168

169+
def test_cwe(tmpdir):
170+
# Trac 14323 - addon warnings with cwe
171+
test_file = os.path.join(tmpdir, 'test.c')
172+
addon_file = os.path.join(tmpdir, 'premiumaddon.py')
173+
174+
with open(test_file, 'wt') as f:
175+
f.write('void foo();\n')
176+
177+
args = [f"--addon={addon_file}", '--xml', test_file]
178+
179+
with open(addon_file, 'wt') as f:
180+
f.write('print(\'{"addon":"a","column":1,"errorId":"id","extra":"","file":"test.c","cwe":123,"linenr":1,"message":"bug","severity":"error"}\')')
181+
182+
_, _, stderr = cppcheck(args)
183+
assert '<error id="a-id" severity="error" msg="bug" verbose="bug" cwe="123" ' in stderr
184+
185+
169186
def test_hash(tmpdir):
170187
# Trac 14225 - warnings with hash
171188
test_file = os.path.join(tmpdir, 'test.c')

0 commit comments

Comments
 (0)