Skip to content

Commit b95abc9

Browse files
committed
Simplify initialization of fileName member of Rule instances
1 parent 5dac8ef commit b95abc9

13 files changed

+27
-28
lines changed

headers/modsecurity/rule.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ using MatchActions = std::vector<actions::Action *>;
6464

6565
class Rule {
6666
public:
67-
Rule(std::unique_ptr<std::string> fileName, int lineNumber)
68-
: m_fileName(*fileName),
67+
Rule(const std::string &fileName, int lineNumber)
68+
: m_fileName(fileName),
6969
m_lineNumber(lineNumber),
7070
m_phase(modsecurity::Phases::RequestHeadersPhase) {
7171
}

headers/modsecurity/rule_marker.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ class RuleMarker : public Rule {
3333
public:
3434
RuleMarker(
3535
const std::string &name,
36-
std::unique_ptr<std::string> fileName,
36+
const std::string &fileName,
3737
int lineNumber)
38-
: Rule(std::move(fileName), lineNumber),
38+
: Rule(fileName, lineNumber),
3939
m_name(name) { }
4040

4141
RuleMarker(const RuleMarker &r) = delete;

headers/modsecurity/rule_unconditional.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ class RuleUnconditional : public RuleWithActions {
3737
RuleUnconditional(
3838
std::vector<actions::Action *> *actions,
3939
Transformations *transformations,
40-
std::unique_ptr<std::string> fileName,
40+
const std::string &fileName,
4141
int lineNumber)
42-
: RuleWithActions(actions, transformations, std::move(fileName), lineNumber) { }
42+
: RuleWithActions(actions, transformations, fileName, lineNumber) { }
4343

4444
RuleUnconditional(const RuleUnconditional& r) = delete;
4545

headers/modsecurity/rule_with_actions.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class RuleWithActions : public Rule {
4040
RuleWithActions(
4141
Actions *a,
4242
Transformations *t,
43-
std::unique_ptr<std::string> fileName,
43+
const std::string &fileName,
4444
int lineNumber);
4545

4646
virtual ~RuleWithActions();

headers/modsecurity/rule_with_operator.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class RuleWithOperator : public RuleWithActions {
4242
variables::Variables *variables,
4343
std::vector<actions::Action *> *actions,
4444
Transformations *transformations,
45-
std::unique_ptr<std::string> fileName,
45+
const std::string &fileName,
4646
int lineNumber);
4747

4848
virtual ~RuleWithOperator();

src/parser/driver.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,10 @@ Driver::~Driver() {
4343
}
4444

4545

46-
int Driver::addSecMarker(const std::string& marker, std::unique_ptr<std::string> fileName, int lineNumber) {
46+
int Driver::addSecMarker(const std::string& marker, const std::string &fileName, int lineNumber) {
4747
// FIXME: we might move this to the parser.
4848
for (int i = 0; i < modsecurity::Phases::NUMBER_OF_PHASES; i++) {
49-
RuleMarker *r = new RuleMarker(marker, std::unique_ptr<std::string>(new std::string(*fileName)), lineNumber);
50-
std::unique_ptr<RuleMarker> rule(r);
49+
auto rule = std::make_unique<RuleMarker>(marker, fileName, lineNumber);
5150
rule->setPhase(i);
5251
m_rulesSetPhases.insert(std::move(rule));
5352
}

src/parser/driver.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Driver : public RulesSetProperties {
6060

6161
int addSecRule(std::unique_ptr<RuleWithActions> rule);
6262
int addSecAction(std::unique_ptr<RuleWithActions> rule);
63-
int addSecMarker(const std::string& marker, std::unique_ptr<std::string> fileName, int lineNumber);
63+
int addSecMarker(const std::string& marker, const std::string &fileName, int lineNumber);
6464
int addSecRuleScript(std::unique_ptr<RuleScript> rule);
6565

6666
bool scan_begin();

src/parser/seclang-parser.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -2313,7 +2313,7 @@ namespace yy {
23132313
/* variables */ v,
23142314
/* actions */ a,
23152315
/* transformations */ t,
2316-
/* file name */ std::unique_ptr<std::string>(new std::string(*yystack_[3].location.end.filename)),
2316+
/* file name */ std::string(*yystack_[3].location.end.filename),
23172317
/* line number */ yystack_[3].location.end.line
23182318
));
23192319

@@ -2337,7 +2337,7 @@ namespace yy {
23372337
/* variables */ v,
23382338
/* actions */ NULL,
23392339
/* transformations */ NULL,
2340-
/* file name */ std::unique_ptr<std::string>(new std::string(*yystack_[2].location.end.filename)),
2340+
/* file name */ std::string(*yystack_[2].location.end.filename),
23412341
/* line number */ yystack_[2].location.end.line
23422342
));
23432343
if (driver.addSecRule(std::move(rule)) == false) {
@@ -2363,7 +2363,7 @@ namespace yy {
23632363
std::unique_ptr<RuleUnconditional> rule(new RuleUnconditional(
23642364
/* actions */ a,
23652365
/* transformations */ t,
2366-
/* file name */ std::unique_ptr<std::string>(new std::string(*yystack_[1].location.end.filename)),
2366+
/* file name */ std::string(*yystack_[1].location.end.filename),
23672367
/* line number */ yystack_[1].location.end.line
23682368
));
23692369
driver.addSecAction(std::move(rule));
@@ -2389,7 +2389,7 @@ namespace yy {
23892389
/* path to script */ yystack_[1].value.as < std::string > (),
23902390
/* actions */ a,
23912391
/* transformations */ t,
2392-
/* file name */ std::unique_ptr<std::string>(new std::string(*yystack_[1].location.end.filename)),
2392+
/* file name */ std::string(*yystack_[1].location.end.filename),
23932393
/* line number */ yystack_[1].location.end.line
23942394
));
23952395

@@ -2469,7 +2469,7 @@ namespace yy {
24692469
#line 1241 "seclang-parser.yy"
24702470
{
24712471
driver.addSecMarker(modsecurity::utils::string::removeBracketsIfNeeded(yystack_[0].value.as < std::string > ()),
2472-
/* file name */ std::unique_ptr<std::string>(new std::string(*yystack_[0].location.end.filename)),
2472+
/* file name */ std::string(*yystack_[0].location.end.filename),
24732473
/* line number */ yystack_[0].location.end.line
24742474
);
24752475
}

src/parser/seclang-parser.yy

+5-5
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ expression:
11041104
/* variables */ v,
11051105
/* actions */ a,
11061106
/* transformations */ t,
1107-
/* file name */ std::unique_ptr<std::string>(new std::string(*@1.end.filename)),
1107+
/* file name */ std::string(*@1.end.filename),
11081108
/* line number */ @1.end.line
11091109
));
11101110

@@ -1124,7 +1124,7 @@ expression:
11241124
/* variables */ v,
11251125
/* actions */ NULL,
11261126
/* transformations */ NULL,
1127-
/* file name */ std::unique_ptr<std::string>(new std::string(*@1.end.filename)),
1127+
/* file name */ std::string(*@1.end.filename),
11281128
/* line number */ @1.end.line
11291129
));
11301130
if (driver.addSecRule(std::move(rule)) == false) {
@@ -1146,7 +1146,7 @@ expression:
11461146
std::unique_ptr<RuleUnconditional> rule(new RuleUnconditional(
11471147
/* actions */ a,
11481148
/* transformations */ t,
1149-
/* file name */ std::unique_ptr<std::string>(new std::string(*@1.end.filename)),
1149+
/* file name */ std::string(*@1.end.filename),
11501150
/* line number */ @1.end.line
11511151
));
11521152
driver.addSecAction(std::move(rule));
@@ -1168,7 +1168,7 @@ expression:
11681168
/* path to script */ $1,
11691169
/* actions */ a,
11701170
/* transformations */ t,
1171-
/* file name */ std::unique_ptr<std::string>(new std::string(*@1.end.filename)),
1171+
/* file name */ std::string(*@1.end.filename),
11721172
/* line number */ @1.end.line
11731173
));
11741174

@@ -1240,7 +1240,7 @@ expression:
12401240
| CONFIG_DIR_SEC_MARKER
12411241
{
12421242
driver.addSecMarker(modsecurity::utils::string::removeBracketsIfNeeded($1),
1243-
/* file name */ std::unique_ptr<std::string>(new std::string(*@1.end.filename)),
1243+
/* file name */ std::string(*@1.end.filename),
12441244
/* line number */ @1.end.line
12451245
);
12461246
}

src/rule_script.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ class RuleScript : public RuleWithActions {
4747
RuleScript(const std::string &name,
4848
std::vector<Action *> *actions,
4949
Transformations *t,
50-
std::unique_ptr<std::string> fileName,
50+
const std::string &fileName,
5151
int lineNumber)
52-
: RuleWithActions(actions, t, std::move(fileName), lineNumber),
52+
: RuleWithActions(actions, t, fileName, lineNumber),
5353
m_name(name),
5454
m_lua() { }
5555

src/rule_with_actions.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ using actions::transformations::Transformation;
5959
RuleWithActions::RuleWithActions(
6060
Actions *actions,
6161
Transformations *transformations,
62-
std::unique_ptr<std::string> fileName,
62+
const std::string &fileName,
6363
int lineNumber)
64-
: Rule(std::move(fileName), lineNumber),
64+
: Rule(fileName, lineNumber),
6565
m_rev(""),
6666
m_ver(""),
6767
m_accuracy(0),

src/rule_with_operator.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ RuleWithOperator::RuleWithOperator(Operator *op,
5555
variables::Variables *_variables,
5656
std::vector<Action *> *actions,
5757
Transformations *transformations,
58-
std::unique_ptr<std::string> fileName,
58+
const std::string &fileName,
5959
int lineNumber)
6060
: RuleWithActions(actions, transformations, std::move(fileName), lineNumber),
6161
m_variables(_variables),

src/variables/variable.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ class VariableMonkeyResolution {
379379

380380
static std::string stringMatchResolve(Transaction *t,
381381
const std::string &variable) {
382-
std::unique_ptr<std::string> vv = nullptr;
382+
std::unique_ptr<std::string> vv;
383383
size_t collection = variable.find(".");
384384
if (collection == std::string::npos) {
385385
collection = variable.find(":");

0 commit comments

Comments
 (0)