Skip to content

Commit c31e0f0

Browse files
committed
defect: provide an explicit constructor
... that initializes checker to a specified value
1 parent 6f2454a commit c31e0f0

File tree

2 files changed

+23
-30
lines changed

2 files changed

+23
-30
lines changed

src/csparser.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,8 @@ EToken ErrFileLexer::readNext()
165165
boost::smatch sm;
166166

167167
if (boost::regex_match(line, sm, reChecker_)) {
168-
def_ = Defect();
169-
def_.checker = sm[/* checker */ 1];
170-
def_.annotation = sm[/* annotat */ 2];
168+
def_ = Defect(sm[/* checker */ 1]);
169+
def_.annotation = sm[/* annotation */ 2];
171170
return T_CHECKER;
172171
}
173172

src/defect.hh

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,16 @@
4545

4646

4747
struct DefEvent {
48-
std::string fileName;
49-
int line;
50-
int column;
51-
std::string event;
52-
std::string msg;
48+
std::string fileName;
49+
int line = 0;
50+
int column = 0;
51+
std::string event;
52+
std::string msg;
5353

5454
/// 0 = key event, 1 = info event, 2 = trace event
55-
int verbosityLevel;
55+
int verbosityLevel = 0;
5656

57-
DefEvent():
58-
line(0),
59-
column(0),
60-
verbosityLevel(0)
61-
{
62-
}
57+
DefEvent() { }
6358
};
6459

6560
inline bool cmpEvents(bool *pResult, const DefEvent &a, const DefEvent &b)
@@ -85,21 +80,20 @@ inline bool operator<(const DefEvent &a, const DefEvent &b)
8580
typedef std::vector<DefEvent> TEvtList;
8681

8782
struct Defect {
88-
std::string checker;
89-
std::string annotation;
90-
TEvtList events;
91-
unsigned keyEventIdx; ///< in range 0..(events.size()-1)
92-
int cwe; ///< CWE number, 0 means unused
93-
int imp; ///< "important" flag, bool for now
94-
int defectId; ///< used only by the JSON format
95-
std::string function; ///< used only by the JSON format
96-
std::string language; ///< used only by the JSON format
97-
98-
Defect():
99-
keyEventIdx(0U),
100-
cwe(0),
101-
imp(0),
102-
defectId(0)
83+
std::string checker;
84+
std::string annotation;
85+
TEvtList events;
86+
unsigned keyEventIdx = 0U; ///< in range 0..(events.size()-1)
87+
int cwe = 0; ///< CWE number, 0 means unused
88+
int imp = 0; ///< "important" flag, bool for now
89+
int defectId = 0; ///< used only by the JSON format
90+
std::string function; ///< used only by the JSON format
91+
std::string language; ///< used only by the JSON format
92+
93+
Defect() { }
94+
95+
explicit Defect(const std::string checker):
96+
checker(checker)
10397
{
10498
}
10599
};

0 commit comments

Comments
 (0)