Clean up
Turn on werror and wall. Also return emtpy on
MATCH_ONE to discourage template usage.
Change-Id: I1b987d901d251c61b846ee88a3b95df36d59d439
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6bc5362..10d542e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,9 +3,12 @@
include (ExternalProject)
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
-set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lstdc++fs")
set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
-set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
+set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -Werror -Wall")
+
+# todo: fix these warnings
+set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-aliasing -Wno-catch-value")
+
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-rtti")
option (YOCTO "Enable Building in Yocto" OFF)
@@ -14,8 +17,8 @@
if (NOT YOCTO)
externalproject_add (
Boost URL
- https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.gz
- URL_MD5 d275cd85b00022313c171f602db59fc5 SOURCE_DIR
+ https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_69_0.tar.gz
+ URL_MD5 b50944c0c13f81ce2c006802a1186f5a SOURCE_DIR
"${CMAKE_BINARY_DIR}/boost-src" BINARY_DIR
"${CMAKE_BINARY_DIR}/boost-build" CONFIGURE_COMMAND "" BUILD_COMMAND ""
INSTALL_COMMAND mkdir -p "${CMAKE_BINARY_DIR}/prefix/include/" && cp -R
diff --git a/src/EntityManager.cpp b/src/EntityManager.cpp
index 35fadb9..fb75856 100644
--- a/src/EntityManager.cpp
+++ b/src/EntityManager.cpp
@@ -38,9 +38,7 @@
constexpr const char* schemaDirectory = PACKAGE_DIR "configurations/schemas";
constexpr const char* globalSchema = "global.json";
constexpr const char* TEMPLATE_CHAR = "$";
-constexpr const size_t PROPERTIES_CHANGED_UNTIL_FLUSH_COUNT = 20;
constexpr const int32_t MAX_MAPPER_DEPTH = 0;
-constexpr const size_t SLEEP_AFTER_PROPERTIES_CHANGE_SECONDS = 5;
struct cmp_str
{
@@ -160,8 +158,7 @@
{
for (auto& connPair : object.second)
{
- auto insertPair =
- interfaceConnections.insert(connPair.first);
+ interfaceConnections.insert(connPair.first);
}
}
}
@@ -286,6 +283,11 @@
}
break;
}
+ default:
+ {
+ std::cerr << "unexpected dbus probe type "
+ << match.second.type_name() << "\n";
+ }
}
}
else
@@ -342,12 +344,10 @@
case probe_type_codes::FALSE_T:
{
return false;
- break;
}
case probe_type_codes::TRUE_T:
{
return true;
- break;
}
case probe_type_codes::MATCH_ONE:
{
@@ -367,7 +367,7 @@
{
if (!std::regex_search(probe, match, command))
{
- std::cerr << "found probe sytax error " << probe
+ std::cerr << "found probe syntax error " << probe
<< "\n";
return false;
}
@@ -377,6 +377,10 @@
commandStr) != PASSED_PROBES.end());
break;
}
+ default:
+ {
+ break;
+ }
}
}
// look on dbus for object
@@ -384,7 +388,7 @@
{
if (!std::regex_search(probe, match, command))
{
- std::cerr << "dbus probe sytax error " << probe << "\n";
+ std::cerr << "dbus probe syntax error " << probe << "\n";
return false;
}
std::string commandStr = *(match.begin() + 1);
@@ -394,7 +398,7 @@
auto json = nlohmann::json::parse(commandStr, nullptr, false);
if (json.is_discarded())
{
- std::cerr << "dbus command sytax error " << commandStr << "\n";
+ std::cerr << "dbus command syntax error " << commandStr << "\n";
return false;
}
// we can match any (string, variant) property. (string, string)
@@ -436,9 +440,14 @@
foundDevs.emplace_back(
boost::container::flat_map<std::string, BasicVariantType>());
}
- if (matchOne && foundDevs.size() > 1)
+ if (matchOne && ret)
{
- foundDevs.erase(foundDevs.begin() + 1, foundDevs.end());
+ // match one could match multiple dbus values, which means we don't care
+ // what one we found so we shouldn't be using template replace. return
+ // an empty one
+ foundDevs.clear();
+ foundDevs.emplace_back(
+ boost::container::flat_map<std::string, BasicVariantType>());
}
return ret;
}
@@ -456,9 +465,11 @@
}
~PerformProbe()
{
- if (probe(_probeCommand, _foundDevs))
+ std::vector<boost::container::flat_map<std::string, BasicVariantType>>
+ foundDevs;
+ if (probe(_probeCommand, foundDevs))
{
- _callback(_foundDevs);
+ _callback(foundDevs);
}
}
void run()
@@ -467,7 +478,6 @@
boost::container::flat_map<const char*, probe_type_codes,
cmp_str>::const_iterator probeType;
- std::vector<std::string> dbusProbes;
for (std::string& probe : _probeCommand)
{
bool found = false;
@@ -497,8 +507,6 @@
std::function<void(std::vector<boost::container::flat_map<
std::string, BasicVariantType>>&)>
_callback;
- std::vector<boost::container::flat_map<std::string, BasicVariantType>>
- _foundDevs;
};
// writes output files to persist data
@@ -793,6 +801,11 @@
}
break;
}
+ default:
+ {
+ std::cerr << "Unexpected json type in system configuration \n";
+ break;
+ }
}
}
if (permission == sdbusplus::asio::PropertyPermission::readWrite)
@@ -925,7 +938,6 @@
for (auto& boardPair : newConfiguration.items())
{
std::string boardKey = boardPair.key();
- std::vector<std::string> path;
std::string jsonPointerPath = "/" + boardKey;
// loop through newConfiguration, but use values from system
// configuration to be able to modify via dbus later
@@ -1129,8 +1141,6 @@
boost::replace_all(*strPtr, "$index", std::to_string(foundDeviceIdx));
- std::size_t templateIndex = 0;
-
for (auto& foundDevicePair : foundDevice)
{
std::string templateName = "$" + foundDevicePair.first;
@@ -1311,7 +1321,7 @@
PASSED_PROBES.push_back(name);
size_t foundDeviceIdx = 0;
- // insert into configuration temporarly to be able to
+ // insert into configuration temporarily to be able to
// reference ourselves
_systemConfiguration[name] = *record;
diff --git a/src/FruDevice.cpp b/src/FruDevice.cpp
index 9d0beff..3c42515 100644
--- a/src/FruDevice.cpp
+++ b/src/FruDevice.cpp
@@ -136,8 +136,8 @@
{
continue;
}
- auto [_, inserted] = foundOffsets.insert(blockData[ii]);
- if (!inserted)
+ auto inserted = foundOffsets.insert(blockData[ii]);
+ if (!inserted.second)
{
return false;
}
@@ -210,7 +210,7 @@
device.insert(device.end(), block_data.begin(),
block_data.begin() + 8);
- for (int jj = 1; jj <= FRU_AREAS.size(); jj++)
+ for (size_t jj = 1; jj <= FRU_AREAS.size(); jj++)
{
auto area_offset = device[jj];
if (area_offset != 0)
@@ -392,8 +392,6 @@
"VERSION", "SERIAL_NUMBER", "ASSET_TAG",
"FRU_VERSION_ID", "INFO_AM1", "INFO_AM2"};
- size_t sum = 0;
-
if (fruBytes.size() <= 8)
{
return false;
@@ -404,7 +402,7 @@
const std::vector<const char*>* fieldData;
- for (auto& area : FRU_AREAS)
+ for (const std::string& area : FRU_AREAS)
{
fruAreaOffsetField++;
if (fruAreaOffsetField >= fruBytes.end())
@@ -495,7 +493,7 @@
.base(),
value.end());
- result[std::string(area) + "_" + field] = std::move(value);
+ result[area + "_" + field] = std::move(value);
fruBytesIter += length;
if (fruBytesIter >= fruBytes.end())
@@ -872,8 +870,8 @@
eventHandler);
int fd = inotify_init();
- int wd = inotify_add_watch(fd, I2C_DEV_LOCATION,
- IN_CREATE | IN_MOVED_TO | IN_DELETE);
+ inotify_add_watch(fd, I2C_DEV_LOCATION,
+ IN_CREATE | IN_MOVED_TO | IN_DELETE);
std::array<char, 4096> readBuffer;
std::string pendingBuffer;
// monitor for new i2c devices