Skip to content

Commit

Permalink
cwe-mapper: do not assign CWE to unknown events of Cppcheck
Browse files Browse the repository at this point in the history
Reported-by: Steve Grubb
  • Loading branch information
kdudka committed Apr 30, 2018
1 parent 9ef50a2 commit 142ee3f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cwe-mapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,25 @@ bool CweMap::assignCwe(Defect &def) const {
}

// lookup by event
int &cweDst = def.cwe;
const Private::TNumByEvent &row = rowIt->second;
const DefEvent &evt = def.events[def.keyEventIdx];
Private::TNumByEvent::const_iterator cweIt = row.find(evt.event);
if (row.end() == cweIt) {
if (!d->silent)
std::cerr << "warning: CWE not found: checker = " << def.checker
<< ", event = " << evt.event << "\n";

if (def.checker == "CPPCHECK_WARNING") {
// we cannot fallback to a random CWE that Cppcheck has mapping for
cweDst = 0;
return false;
}

cweIt = row.begin();
}

const int cweSrc = cweIt->second;
int &cweDst = def.cwe;
if (cweSrc == cweDst)
// already assigned
return true;
Expand Down

0 comments on commit 142ee3f

Please sign in to comment.