File tree Expand file tree Collapse file tree 5 files changed +22
-2
lines changed
Expand file tree Collapse file tree 5 files changed +22
-2
lines changed Original file line number Diff line number Diff line change 1+ "cwe_id","name"
12"15","External Control of System or Configuration Setting"
23"19","Data Processing Errors"
34"20","Improper Input Validation"
306307"663","Use of a Non-reentrant Function in a Concurrent Context"
307308"664","Improper Control of a Resource Through its Lifetime"
308309"665","Improper Initialization"
309- "667", "Improper Locking"
310+ "667","Improper Locking"
310311"670","Always-Incorrect Control Flow Implementation"
311312"672","Operation on a Resource after Expiration or Release"
312313"674","Uncontrolled Recursion"
Original file line number Diff line number Diff line change @@ -53,7 +53,11 @@ bool AbstractCsvParser::parse(InStream &ins)
5353 // break the current line into fields
5454 const TStringList fields (tok.begin (), tok.end ());
5555
56- // call the template method
56+ // call the template method for CSV header
57+ if (1 == d->lineno && /* handled */ this ->handleHeader (fields))
58+ continue ;
59+
60+ // call the template method for CSV data
5761 if (!/* continue */ this ->handleLine (fields))
5862 break ;
5963 }
Original file line number Diff line number Diff line change @@ -39,6 +39,12 @@ class AbstractCsvParser {
3939 protected:
4040 using TStringList = std::vector<std::string>;
4141
42+ // / called for the first line only
43+ virtual bool /* handled */ handleHeader(const TStringList &) {
44+ // returning false causes handleLine() to be called as a fallback
45+ return false ;
46+ }
47+
4248 virtual bool /* continue */ handleLine(const TStringList &) = 0 ;
4349 void parseError (const std::string &msg);
4450
Original file line number Diff line number Diff line change @@ -36,6 +36,14 @@ CweNameLookup::CweNameLookup():
3636
3737CweNameLookup::~CweNameLookup () = default ;
3838
39+ bool CweNameLookup::handleHeader (const TStringList &fields)
40+ {
41+ // "cwe_id", "name" is recognized as the CSV header for cwe-names.csv
42+ return 2U == fields.size ()
43+ && " cwe_id" == fields[0 ]
44+ && " name" == fields[1 ];
45+ }
46+
3947bool CweNameLookup::handleLine (const TStringList &fields)
4048{
4149 if (2U != fields.size ()) {
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ class CweNameLookup: public AbstractCsvParser {
3434 const std::string& lookup (int cwe) const ;
3535
3636 protected:
37+ bool /* handled */ handleHeader(const TStringList &) override ;
3738 bool /* continue */ handleLine(const TStringList &) override ;
3839
3940 private:
You can’t perform that action at this time.
0 commit comments