clang-tidy: Enable bugprone-narrowing-conversions
Modified code to address issues flagged by this check.
Tested: Build and unit tests passed successfully.
Change-Id: I17111e3f00ad0dbf5d0d72d5ccd374367e4cca36
Signed-off-by: Jayanth Othayoth <ojayanth@gmail.com>
diff --git a/.clang-tidy b/.clang-tidy
index 3322c6f..cf85fa8 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -32,6 +32,7 @@
bugprone-multi-level-implicit-pointer-conversion,
bugprone-multiple-new-in-one-expression,
bugprone-multiple-statement-macro,
+bugprone-narrowing-conversions,
bugprone-no-escape,
bugprone-non-zero-enum-to-bool-conversion,
bugprone-not-null-terminated-result,
diff --git a/certs_manager.cpp b/certs_manager.cpp
index dc991d5..cf61d4f 100644
--- a/certs_manager.cpp
+++ b/certs_manager.cpp
@@ -700,7 +700,8 @@
}
if ((EVP_PKEY_keygen_init(ctx.get()) <= 0) ||
- (EVP_PKEY_CTX_set_rsa_keygen_bits(ctx.get(), keyBitLen) <= 0))
+ (EVP_PKEY_CTX_set_rsa_keygen_bits(ctx.get(),
+ static_cast<int>(keyBitLen)) <= 0))
{
lg2::error("Error occurred initializing keygen context");
diff --git a/mainapp.cpp b/mainapp.cpp
index 5e47aeb..3a88231 100644
--- a/mainapp.cpp
+++ b/mainapp.cpp
@@ -35,7 +35,7 @@
std::string res = s;
if (!res.empty())
{
- res[0] = std::toupper(res[0]);
+ res[0] = static_cast<char>(std::toupper(res[0]));
}
return res;
}
diff --git a/watch.cpp b/watch.cpp
index 933e5ab..8c5842c 100644
--- a/watch.cpp
+++ b/watch.cpp
@@ -77,7 +77,7 @@
event, fd, EPOLLIN, [this](sdeventplus::source::IO&, int fd, uint32_t) {
constexpr int size = sizeof(struct inotify_event) + NAME_MAX + 1;
std::array<char, size> buffer{};
- int length = read(fd, buffer.data(), buffer.size());
+ ssize_t length = read(fd, buffer.data(), buffer.size());
if (length >= static_cast<int>(sizeof(struct inotify_event)))
{
struct inotify_event* notifyEvent =