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"
1
2
"15","External Control of System or Configuration Setting"
2
3
"19","Data Processing Errors"
3
4
"20","Improper Input Validation"
306
307
"663","Use of a Non-reentrant Function in a Concurrent Context"
307
308
"664","Improper Control of a Resource Through its Lifetime"
308
309
"665","Improper Initialization"
309
- "667", "Improper Locking"
310
+ "667","Improper Locking"
310
311
"670","Always-Incorrect Control Flow Implementation"
311
312
"672","Operation on a Resource after Expiration or Release"
312
313
"674","Uncontrolled Recursion"
Original file line number Diff line number Diff line change @@ -53,7 +53,11 @@ bool AbstractCsvParser::parse(InStream &ins)
53
53
// break the current line into fields
54
54
const TStringList fields (tok.begin (), tok.end ());
55
55
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
57
61
if (!/* continue */ this ->handleLine (fields))
58
62
break ;
59
63
}
Original file line number Diff line number Diff line change @@ -39,6 +39,12 @@ class AbstractCsvParser {
39
39
protected:
40
40
using TStringList = std::vector<std::string>;
41
41
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
+
42
48
virtual bool /* continue */ handleLine(const TStringList &) = 0 ;
43
49
void parseError (const std::string &msg);
44
50
Original file line number Diff line number Diff line change @@ -36,6 +36,14 @@ CweNameLookup::CweNameLookup():
36
36
37
37
CweNameLookup::~CweNameLookup () = default ;
38
38
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
+
39
47
bool CweNameLookup::handleLine (const TStringList &fields)
40
48
{
41
49
if (2U != fields.size ()) {
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ class CweNameLookup: public AbstractCsvParser {
34
34
const std::string& lookup (int cwe) const ;
35
35
36
36
protected:
37
+ bool /* handled */ handleHeader(const TStringList &) override ;
37
38
bool /* continue */ handleLine(const TStringList &) override ;
38
39
39
40
private:
You can’t perform that action at this time.
0 commit comments