build: enable and fix -Wconversion,-Wsign-conversion
Fix instances of cppcoreguidelines-narrowing-conversions, and enable the
warnings to catch future cases. Tested by building and running the unit
tests.
Change-Id: I4047acd87a5ac6050ed7650e1efd32a921574041
Signed-off-by: Brad Bishop <bradbish@qti.qualcomm.com>
diff --git a/meson.build b/meson.build
index 7945276..4508e20 100644
--- a/meson.build
+++ b/meson.build
@@ -23,7 +23,9 @@
add_project_arguments(
'-Wformat=2',
'-Wcast-align',
+ '-Wconversion',
'-Woverloaded-virtual',
+ '-Wsign-conversion',
'-Wunused',
'-Wduplicated-cond',
'-Wduplicated-branches',
diff --git a/src/handler.cpp b/src/handler.cpp
index 8caba42..9a5244e 100644
--- a/src/handler.cpp
+++ b/src/handler.cpp
@@ -5,6 +5,7 @@
#include <xyz/openbmc_project/Common/error.hpp>
#include <algorithm>
+#include <iterator>
#include <string>
#include <unordered_set>
#include <utility>
@@ -176,8 +177,10 @@
if (thisPath.starts_with(reqPath))
{
// count the number of slashes past the stripped search term
- int32_t thisDepth = std::count(
- thisPath.begin() + reqPathStripped.size(), thisPath.end(), '/');
+ auto thisDepth = std::count(
+ thisPath.begin() + std::distance(reqPathStripped.begin(),
+ reqPathStripped.end()),
+ thisPath.end(), '/');
if (thisDepth <= depth)
{
for (const auto& interfaceMap : objectPath.second)
@@ -244,8 +247,10 @@
if (thisPath.starts_with(reqPath))
{
// count the number of slashes past the stripped search term
- int thisDepth = std::count(
- thisPath.begin() + reqPathStripped.size(), thisPath.end(), '/');
+ auto thisDepth = std::count(
+ thisPath.begin() + std::distance(reqPathStripped.begin(),
+ reqPathStripped.end()),
+ thisPath.end(), '/');
if (thisDepth <= depth)
{
bool add = interfaces.empty();