Skip to content

Commit 400a7a0

Browse files
committed
cslinker --cwelist: do not warn about missing CWE mapping
... in case a CWE is assigned already
1 parent b78b49f commit 400a7a0

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

cwe-mapper.cc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,30 @@ bool CweMap::loadCweMap(std::istream &str, const std::string &fileName) {
118118
}
119119

120120
bool CweMap::assignCwe(Defect &def) const {
121+
int &cweDst = def.cwe;
122+
121123
// lookup by checker
122124
Private::TMapByChk::const_iterator rowIt = d->mapByChk.find(def.checker);
123125
if (d->mapByChk.end() == rowIt) {
126+
if (cweDst)
127+
// CWE already assigned, stay silent
128+
return true;
129+
124130
if (!d->silent)
125131
std::cerr << "warning: CWE not found: checker = "
126132
<< def.checker <<"\n";
127133
return false;
128134
}
129135

130136
// lookup by event
131-
int &cweDst = def.cwe;
132137
const Private::TNumByEvent &row = rowIt->second;
133138
const DefEvent &evt = def.events[def.keyEventIdx];
134139
Private::TNumByEvent::const_iterator cweIt = row.find(evt.event);
135140
if (row.end() == cweIt) {
141+
if (cweDst)
142+
// CWE already assigned, stay silent
143+
return true;
144+
136145
if (!d->silent)
137146
std::cerr << "warning: CWE not found: checker = " << def.checker
138147
<< ", event = " << evt.event << "\n";
@@ -148,7 +157,7 @@ bool CweMap::assignCwe(Defect &def) const {
148157

149158
const int cweSrc = cweIt->second;
150159
if (cweSrc == cweDst)
151-
// already assigned
160+
// already assigned to the requested value
152161
return true;
153162

154163
if (cweDst && !d->silent)

0 commit comments

Comments
 (0)