Skip to content

Commit 6eae191

Browse files
committed
cslinker --implist: mark reports from the specified list as important
1 parent f7d6f5b commit 6eae191

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

cslinker.cc

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "abstract-parser.hh"
2121
#include "cwe-mapper.hh"
22+
#include "deflookup.hh"
2223
#include "defqueue.hh"
2324
#include "instream.hh"
2425
#include "json-writer.hh"
@@ -85,6 +86,37 @@ bool loadPropsFromIniFile(
8586
}
8687
}
8788

89+
class ImpFlagDecorator: public GenericAbstractFilter {
90+
public:
91+
ImpFlagDecorator(AbstractWriter *writer):
92+
GenericAbstractFilter(writer)
93+
{
94+
}
95+
96+
void hashImpDefect(const Defect &);
97+
98+
virtual void handleDef(const Defect &def);
99+
100+
private:
101+
DefLookup impSet_;
102+
};
103+
104+
void ImpFlagDecorator::hashImpDefect(const Defect &impDef) {
105+
impSet_.hashDefect(impDef);
106+
}
107+
108+
void ImpFlagDecorator::handleDef(const Defect &defOrig) {
109+
if (impSet_.lookup(defOrig)) {
110+
// found -> set "imp" flag to 1
111+
Defect def = defOrig;
112+
def.imp = 1;
113+
slave_->handleDef(def);
114+
}
115+
else {
116+
slave_->handleDef(defOrig);
117+
}
118+
}
119+
88120
class OrphanWriter {
89121
public:
90122
OrphanWriter(AbstractWriter &writer):
@@ -159,6 +191,8 @@ int main(int argc, char *argv[]) {
159191
desc.add_options()
160192
("cwelist", po::value<string>(),
161193
"(re)assign CWE numbers to defects by the given CSV list")
194+
("implist", po::value<string>(),
195+
"mark reports from the specified list as important")
162196
("inifile", po::value<string>(),
163197
"load scan properties from the given INI file")
164198
("mapfile", po::value<string>(),
@@ -199,6 +233,7 @@ int main(int argc, char *argv[]) {
199233
}
200234

201235
const string fnCwe = valueOf<string>(vm["cwelist"]);
236+
const string fnImp = valueOf<string>(vm["implist"]);
202237
const string fnIni = valueOf<string>(vm["inifile"]);
203238
const string fnMap = valueOf<string>(vm["mapfile"]);
204239
const bool silent = vm.count("quiet");
@@ -213,7 +248,9 @@ int main(int argc, char *argv[]) {
213248
return 1;
214249
}
215250

216-
CweMapDecorator writer(new JsonWriter(std::cout), silent);
251+
AbstractWriter *jsonWriter = new JsonWriter(std::cout);
252+
ImpFlagDecorator *impDec = new ImpFlagDecorator(jsonWriter);
253+
CweMapDecorator writer(impDec, silent);
217254

218255
DefQueue defQueue;
219256

@@ -232,6 +269,21 @@ int main(int argc, char *argv[]) {
232269
}
233270
}
234271

272+
if (!fnImp.empty()) {
273+
try {
274+
// load list of important defects
275+
InStream strImp(fnImp.c_str());
276+
Parser pImp(strImp.str(), fnImp);
277+
Defect defImp;
278+
while (pImp.getNext(&defImp))
279+
impDec->hashImpDefect(defImp);
280+
}
281+
catch (const InFileException &e) {
282+
printError(e);
283+
hasError = true;
284+
}
285+
}
286+
235287
const unsigned filesCnt = files.size();
236288
if (!filesCnt && !fnIni.empty() && !loadPropsFromIniFile(writer, fnIni))
237289
hasError = true;

0 commit comments

Comments
 (0)