clang-tidy: Enable bugprone-narrowing-conversions
Modified code to address issues flagged by this check.
Tested: Build and unit tests passed successfully.
Change-Id: Idd5e3701725a833324535d29f0bfffb3ba180e88
Signed-off-by: Jayanth Othayoth <ojayanth@gmail.com>
diff --git a/.clang-tidy b/.clang-tidy
index bfa78f0..0fd1d56 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/dump_manager_bmc.cpp b/dump_manager_bmc.cpp
index a6c64d6..a3402c1 100644
--- a/dump_manager_bmc.cpp
+++ b/dump_manager_bmc.cpp
@@ -309,7 +309,8 @@
{
if (!std::filesystem::is_directory(p))
{
- size += std::ceil(std::filesystem::file_size(p) / 1024.0);
+ std::uintmax_t fileSize = std::filesystem::file_size(p);
+ size += std::ceil(static_cast<double>(fileSize) / 1024.0);
}
}
return size;
diff --git a/dump_offload.cpp b/dump_offload.cpp
index 4958b0c..edf1bff 100644
--- a/dump_offload.cpp
+++ b/dump_offload.cpp
@@ -37,7 +37,7 @@
void writeOnUnixSocket(const int socket, const char* buf,
const uint64_t blockSize)
{
- int numOfBytesWrote = 0;
+ ssize_t numOfBytesWrote = 0;
for (uint64_t i = 0; i < blockSize; i = i + numOfBytesWrote)
{
@@ -199,7 +199,7 @@
// allocate memory to contain file data
std::unique_ptr<char[]> buffer(new char[size]);
// get file data
- pbuf->sgetn(buffer.get(), size);
+ pbuf->sgetn(buffer.get(), static_cast<std::streamsize>(size));
infile.close();
writeOnUnixSocket(socketFD(), buffer.get(), size);