Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/engine/lua.cc
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ int Lua::getvars(lua_State *L) {
variables::Variable::stringMatchResolveMulti(t, varname, &l);

lua_newtable(L);
for (auto i : l) {
for (auto* i : l) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (auto* i : l) {
for (const auto* i : l) {

The original code was written about 8 years ago, the author is no longer involved in development.

If I had to guess why they used value copy mechanism, I would say they wanted to avoid any chance to modify the value on Lua stack (except for intentional change with setvar()).

If we want to keep this restriction, please consider to use const modifier here.

lua_pushnumber(L, idx);
lua_newtable(L);

Expand Down
4 changes: 2 additions & 2 deletions src/rules_exceptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ bool RulesExceptions::contains(int a) {
}
}

for (auto z : m_ranges) {
for (auto& z : m_ranges) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (auto& z : m_ranges) {
for (const auto& z : m_ranges) {

Please see cppcheck's warning:

warning: src/rules_exceptions.cc,198,style,constVariableReference,Variable 'z' can be declared as reference to const

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sonarcloud also reports this.

if (z.first <= a && z.second >= a) {
return true;
}
Expand All @@ -212,7 +212,7 @@ bool RulesExceptions::merge(RulesExceptions *from) {
return ret;
}
}
for (auto b : from->m_ranges) {
for (auto& b : from->m_ranges) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (auto& b : from->m_ranges) {
for (const auto& b : from->m_ranges) {

Please see cppcheck's warning:

warning: src/rules_exceptions.cc,215,style,constVariableReference,Variable 'b' can be declared as reference to const

bool ret = addRange(b.first, b.second);
if (ret == false) {
return ret;
Expand Down
4 changes: 2 additions & 2 deletions src/transaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1700,7 +1700,7 @@ std::string Transaction::toJSON(int parts) {
reinterpret_cast<const unsigned char*>("messages"),
strlen("messages"));
yajl_gen_array_open(g);
for (auto a : m_rulesMessages) {
for (auto& a : m_rulesMessages) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (auto& a : m_rulesMessages) {
for (const auto& a : m_rulesMessages) {

Probably here you could use const too.

yajl_gen_map_open(g);
LOGFY_ADD("message", a.m_message);
yajl_gen_string(g,
Expand All @@ -1721,7 +1721,7 @@ std::string Transaction::toJSON(int parts) {
reinterpret_cast<const unsigned char*>("tags"),
strlen("tags"));
yajl_gen_array_open(g);
for (auto b : a.m_tags) {
for (auto& b : a.m_tags) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (auto& b : a.m_tags) {
for (const auto& b : a.m_tags) {

Probably here you could use const too.

yajl_gen_string(g,
reinterpret_cast<const unsigned char*>(b.data()),
b.length());
Expand Down
Loading