Fix shadowed variable issues
This patchset is the conclusion of a multi-year effort to try to fix
shadowed variable names. Variables seem to be shadowed all over, and in
most places they exist, there's a "code smell" of things that aren't
doing what the author intended.
This commit attempts to clean up these in several ways by:
1. Renaming variables where appropriate.
2. Preferring to refer to member variables directly when operating
within a class
3. Rearranging code so that pass through variables are handled in the
calling scope, rather than passing them through.
These patterns are applied throughout the codebase, to the point where
-Wshadow can be enabled in meson.build.
Tested: Code compiles, unit tests pass. Still need to run redfish
service validator.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: If703398c2282f9e096ca2694fd94515de36a098b
diff --git a/include/ibm/locks.hpp b/include/ibm/locks.hpp
index 7dccbd8..2c6668c 100644
--- a/include/ibm/locks.hpp
+++ b/include/ibm/locks.hpp
@@ -439,19 +439,19 @@
inline Rc Lock::isConflictWithTable(const LockRequests& refLockRequestStructure)
{
- uint32_t transactionId = 0;
+ uint32_t thisTransactionId = 0;
if (lockTable.empty())
{
- transactionId = generateTransactionId();
- BMCWEB_LOG_DEBUG << transactionId;
+ thisTransactionId = generateTransactionId();
+ BMCWEB_LOG_DEBUG << thisTransactionId;
// Lock table is empty, so we are safe to add the lockrecords
// as there will be no conflict
BMCWEB_LOG_DEBUG << "Lock table is empty, so adding the lockrecords";
lockTable.emplace(std::pair<uint32_t, LockRequests>(
- transactionId, refLockRequestStructure));
+ thisTransactionId, refLockRequestStructure));
- return std::make_pair(false, transactionId);
+ return std::make_pair(false, thisTransactionId);
}
BMCWEB_LOG_DEBUG
<< "Lock table is not empty, check for conflict with lock table";
@@ -597,7 +597,7 @@
// compare segment data
- for (uint32_t i = 0; i < p.second; i++)
+ for (uint32_t j = 0; j < p.second; j++)
{
// if the segment data is different, then the locks is on a
// different resource so no conflict between the lock
@@ -610,7 +610,7 @@
if (!(checkByte(
boost::endian::endian_reverse(std::get<3>(refLockRecord1)),
boost::endian::endian_reverse(std::get<3>(refLockRecord2)),
- i)))
+ j)))
{
return false;
}
diff --git a/include/multipart_parser.hpp b/include/multipart_parser.hpp
index 945ebf9..9d801da 100644
--- a/include/multipart_parser.hpp
+++ b/include/multipart_parser.hpp
@@ -198,7 +198,7 @@
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
c = buffer[i];
}
- processPartData(prevIndex, index, buffer, i, c, state);
+ processPartData(prevIndex, buffer, i, c);
break;
case State::END:
break;
@@ -244,8 +244,8 @@
}
}
- void processPartData(size_t& prevIndex, size_t& index, const char* buffer,
- size_t& i, char c, State& state)
+ void processPartData(size_t& prevIndex, const char* buffer, size_t& i,
+ char c)
{
prevIndex = index;
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 1ed695a..7641023 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -2168,9 +2168,9 @@
const char* ifaceName = interface->Attribute("name");
if (ifaceName != nullptr)
{
- nlohmann::json::object_t interface;
- interface["name"] = ifaceName;
- interfacesArray.push_back(std::move(interface));
+ nlohmann::json::object_t interfaceObj;
+ interfaceObj["name"] = ifaceName;
+ interfacesArray.push_back(std::move(interfaceObj));
}
interface = interface->NextSiblingElement("interface");