From d36dbbd6921946966ef8c2d2198eaa1ea1323bce Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 22 Aug 2024 18:41:56 +0200 Subject: [PATCH] iox-#2301 Fix warnings for 32 bit build --- iceoryx_binding_c/source/c_runtime.cpp | 2 +- .../cli/source/command_line_parser.cpp | 2 +- .../container/include/iox/detail/vector.inl | 8 ++--- .../include/iox/detail/static_storage.inl | 2 +- iceoryx_hoofs/memory/include/iox/memory.hpp | 2 +- iceoryx_hoofs/memory/source/memory.cpp | 6 ++-- .../posix/filesystem/source/file.cpp | 8 +++-- .../ipc/include/iox/detail/message_queue.inl | 25 ++++++++------ .../include/iox/detail/unix_domain_socket.inl | 4 +-- .../posix/ipc/include/iox/named_pipe.hpp | 2 +- .../posix/ipc/source/posix_memory_map.cpp | 5 +-- .../posix/ipc/source/posix_shared_memory.cpp | 2 +- .../ipc/source/posix_shared_memory_object.cpp | 2 +- .../posix/ipc/source/unix_domain_socket.cpp | 3 +- .../test_cli_command_line_common.hpp | 4 +-- ...est_container_fixed_position_container.cpp | 4 +-- .../moduletests/test_container_vector.cpp | 8 ++--- .../test_posix_ipc_unix_domain_sockets.cpp | 3 +- .../test_utility_std_string_support.cpp | 2 +- .../test_vocabulary_semantic_string.cpp | 2 +- ...y_string_concatenate_append_and_insert.cpp | 8 ++--- ...test_vocabulary_string_ctor_and_assign.cpp | 4 +-- .../test_mpmc_lockfree_queue_stresstest.cpp | 34 +++++++++---------- ...c_resizeable_lockfree_queue_stresstest.cpp | 32 ++++++++--------- .../include/iox/detail/serialization.inl | 4 +-- .../include/iox/detail/std_string_support.inl | 2 +- .../vocabulary/include/iox/detail/string.inl | 34 ++++++++++--------- iceoryx_posh/experimental/source/node.cpp | 5 +-- .../introspection/mempool_introspection.inl | 2 +- .../roudi/memory/default_roudi_memory.cpp | 19 +++++------ .../test/integrationtests/test_posh_mepoo.cpp | 2 +- .../test/mocks/roudi_memory_provider_mock.hpp | 2 +- .../moduletests/test_mepoo_chunk_header.cpp | 2 +- .../moduletests/test_mepoo_chunk_settings.cpp | 4 +-- .../test_popo_chunk_distributor.cpp | 2 +- .../test/moduletests/test_popo_listener.cpp | 10 +++--- .../iceoryx_posh/testing/mocks/chunk_mock.hpp | 5 +-- .../source/introspection_app.cpp | 34 ++++++++++++++----- 38 files changed, 165 insertions(+), 136 deletions(-) diff --git a/iceoryx_binding_c/source/c_runtime.cpp b/iceoryx_binding_c/source/c_runtime.cpp index e343156f4b..a532046d00 100644 --- a/iceoryx_binding_c/source/c_runtime.cpp +++ b/iceoryx_binding_c/source/c_runtime.cpp @@ -42,7 +42,7 @@ uint64_t iox_runtime_get_instance_name(char* const name, const uint64_t nameLeng } auto instanceName = PoshRuntime::getInstance().getInstanceName(); - std::strncpy(name, instanceName.c_str(), nameLength); + std::strncpy(name, instanceName.c_str(), static_cast(nameLength)); name[nameLength - 1U] = '\0'; // strncpy doesn't add a null-termination if destination is smaller than source return instanceName.size(); diff --git a/iceoryx_hoofs/cli/source/command_line_parser.cpp b/iceoryx_hoofs/cli/source/command_line_parser.cpp index 5d2b83beb9..278f18fe4a 100644 --- a/iceoryx_hoofs/cli/source/command_line_parser.cpp +++ b/iceoryx_hoofs/cli/source/command_line_parser.cpp @@ -106,7 +106,7 @@ bool CommandLineParser::doesNotExceedLongOptionDash(const char* option) const no bool CommandLineParser::doesFitIntoString(const char* value, const uint64_t maxLength) noexcept { - return (strnlen(value, maxLength + 1) <= maxLength); + return (strnlen(value, static_cast(maxLength) + 1) <= maxLength); } bool CommandLineParser::doesOptionNameFitIntoString(const char* option) const noexcept diff --git a/iceoryx_hoofs/container/include/iox/detail/vector.inl b/iceoryx_hoofs/container/include/iox/detail/vector.inl index ae822c2787..6c20aaff20 100644 --- a/iceoryx_hoofs/container/include/iox/detail/vector.inl +++ b/iceoryx_hoofs/container/include/iox/detail/vector.inl @@ -90,7 +90,7 @@ inline vector& vector::operator=(const vector& rhs) no if constexpr (std::is_trivially_copyable::value) { - std::memcpy(data(), rhs.data(), rhsSize * sizeof(T)); + std::memcpy(data(), rhs.data(), static_cast(rhsSize) * sizeof(T)); i = rhsSize; } else @@ -129,7 +129,7 @@ inline vector& vector::operator=(vector&& rhs) noexcep if constexpr (std::is_trivially_copyable::value) { - std::memcpy(data(), rhs.data(), rhsSize * sizeof(T)); + std::memcpy(data(), rhs.data(), static_cast(rhsSize) * sizeof(T)); i = rhsSize; } else @@ -220,7 +220,7 @@ inline bool vector::emplace(const uint64_t position, Targs&&... arg if constexpr (std::is_trivial::value) { resize(size() + 1U); - const uint64_t dataLen{sizeBeforeEmplace - position}; + const size_t dataLen{static_cast(sizeBeforeEmplace) - static_cast(position)}; std::memmove(data() + position + 1U, data() + position, dataLen * sizeof(T)); at_unchecked(position) = T{std::forward(args)...}; } @@ -414,7 +414,7 @@ inline bool vector::erase(iterator position) noexcept at_unchecked(n).~T(); } uint64_t dataLen{size() - n - 1U}; - std::memmove(data() + n, data() + n + 1U, dataLen * sizeof(T)); + std::memmove(data() + n, data() + n + 1U, static_cast(dataLen) * sizeof(T)); } else { diff --git a/iceoryx_hoofs/memory/include/iox/detail/static_storage.inl b/iceoryx_hoofs/memory/include/iox/detail/static_storage.inl index d1b2693d04..2fadf98eea 100644 --- a/iceoryx_hoofs/memory/include/iox/detail/static_storage.inl +++ b/iceoryx_hoofs/memory/include/iox/detail/static_storage.inl @@ -67,7 +67,7 @@ constexpr void* static_storage::allocate(const uint64_t align, size_t space{Capacity}; m_ptr = m_bytes; - if (std::align(align, size, m_ptr, space) != nullptr) + if (std::align(static_cast(align), static_cast(size), m_ptr, space) != nullptr) { // fits, ptr was potentially modified to reflect alignment return m_ptr; diff --git a/iceoryx_hoofs/memory/include/iox/memory.hpp b/iceoryx_hoofs/memory/include/iox/memory.hpp index 6e4638b5ab..5fa2cae9bf 100644 --- a/iceoryx_hoofs/memory/include/iox/memory.hpp +++ b/iceoryx_hoofs/memory/include/iox/memory.hpp @@ -37,7 +37,7 @@ T align(const T value, const T alignment) noexcept /// @param[in] alignment, alignment of the memory /// @param[in] size, memory size /// @return void pointer to the aligned memory -void* alignedAlloc(const uint64_t alignment, const uint64_t size) noexcept; +void* alignedAlloc(const size_t alignment, const size_t size) noexcept; /// @brief frees aligned memory allocated with alignedAlloc /// @param[in] memory, pointer to the aligned memory diff --git a/iceoryx_hoofs/memory/source/memory.cpp b/iceoryx_hoofs/memory/source/memory.cpp index 5d602d87a0..403c255690 100644 --- a/iceoryx_hoofs/memory/source/memory.cpp +++ b/iceoryx_hoofs/memory/source/memory.cpp @@ -21,18 +21,18 @@ namespace iox { -void* alignedAlloc(const uint64_t alignment, const uint64_t size) noexcept +void* alignedAlloc(const size_t alignment, const size_t size) noexcept { // -1 == since the max alignment addition is alignment - 1 otherwise the // memory is already aligned and we have to do nothing // low-level memory management, no other approach then to use malloc to acquire heap memory // NOLINTNEXTLINE(cppcoreguidelines-owning-memory,cppcoreguidelines-pro-type-reinterpret-cast,hicpp-no-malloc,cppcoreguidelines-no-malloc) - auto memory = reinterpret_cast(std::malloc(size + alignment + sizeof(void*) - 1)); + auto memory = reinterpret_cast(std::malloc(size + alignment + sizeof(void*) - 1)); if (memory == 0) { return nullptr; } - uint64_t alignedMemory = align(memory + sizeof(void*), alignment); + size_t alignedMemory = align(memory + sizeof(void*), alignment); assert(alignedMemory >= memory + 1); // low-level memory management, we have to store the actual start of the memory a position before the // returned aligned address to be able to release the actual memory address again with free when we diff --git a/iceoryx_hoofs/posix/filesystem/source/file.cpp b/iceoryx_hoofs/posix/filesystem/source/file.cpp index 2219e2da70..7d5821c60e 100644 --- a/iceoryx_hoofs/posix/filesystem/source/file.cpp +++ b/iceoryx_hoofs/posix/filesystem/source/file.cpp @@ -340,7 +340,9 @@ File::read_at(const uint64_t offset, uint8_t* const buffer, const uint64_t buffe return err(FileReadError::OffsetFailure); } - auto result = IOX_POSIX_CALL(iox_read)(m_file_descriptor, buffer, buffer_len).failureReturnValue(-1).evaluate(); + auto result = IOX_POSIX_CALL(iox_read)(m_file_descriptor, buffer, static_cast(buffer_len)) + .failureReturnValue(-1) + .evaluate(); if (!result.has_error()) { @@ -394,7 +396,9 @@ File::write_at(const uint64_t offset, const uint8_t* const buffer, const uint64_ return err(FileWriteError::OffsetFailure); } - auto result = IOX_POSIX_CALL(iox_write)(m_file_descriptor, buffer, buffer_len).failureReturnValue(-1).evaluate(); + auto result = IOX_POSIX_CALL(iox_write)(m_file_descriptor, buffer, static_cast(buffer_len)) + .failureReturnValue(-1) + .evaluate(); if (!result.has_error()) { diff --git a/iceoryx_hoofs/posix/ipc/include/iox/detail/message_queue.inl b/iceoryx_hoofs/posix/ipc/include/iox/detail/message_queue.inl index d626049228..2a7818452c 100644 --- a/iceoryx_hoofs/posix/ipc/include/iox/detail/message_queue.inl +++ b/iceoryx_hoofs/posix/ipc/include/iox/detail/message_queue.inl @@ -40,7 +40,7 @@ MessageQueue::timedSendImpl(not_null msg, uint64_t msgSize, const u } timespec timeOut = timeout.timespec(units::TimeSpecReference::Epoch); - auto mqCall = IOX_POSIX_CALL(mq_timedsend)(m_mqDescriptor, msg, msgSizeToSend, 1U, &timeOut) + auto mqCall = IOX_POSIX_CALL(mq_timedsend)(m_mqDescriptor, msg, static_cast(msgSizeToSend), 1U, &timeOut) .failureReturnValue(ERROR_CODE) // don't use the suppressErrorMessagesForErrnos method since QNX used EINTR instead of ETIMEDOUT .ignoreErrnos(TIMEOUT_ERRNO) @@ -74,8 +74,9 @@ expected MessageQueue::sendImpl(not_null(msgSizeToSend), 1U) + .failureReturnValue(ERROR_CODE) + .evaluate(); if (mqCall.has_error()) { @@ -95,11 +96,12 @@ expected MessageQueue::timedReceiveImpl(not_null msg, uint64_t maxMsgSize, const units::Duration& timeout) const noexcept { timespec timeOut = timeout.timespec(units::TimeSpecReference::Epoch); - auto mqCall = IOX_POSIX_CALL(mq_timedreceive)(m_mqDescriptor, msg, maxMsgSize, nullptr, &timeOut) - .failureReturnValue(ERROR_CODE) - // don't use the suppressErrorMessagesForErrnos method since QNX used EINTR instead of ETIMEDOUT - .ignoreErrnos(TIMEOUT_ERRNO) - .evaluate(); + auto mqCall = + IOX_POSIX_CALL(mq_timedreceive)(m_mqDescriptor, msg, static_cast(maxMsgSize), nullptr, &timeOut) + .failureReturnValue(ERROR_CODE) + // don't use the suppressErrorMessagesForErrnos method since QNX used EINTR instead of ETIMEDOUT + .ignoreErrnos(TIMEOUT_ERRNO) + .evaluate(); if (mqCall.has_error()) { @@ -118,8 +120,9 @@ template expected MessageQueue::receiveImpl(not_null msg, uint64_t maxMsgSize) const noexcept { - auto mqCall = - IOX_POSIX_CALL(mq_receive)(m_mqDescriptor, msg, maxMsgSize, nullptr).failureReturnValue(ERROR_CODE).evaluate(); + auto mqCall = IOX_POSIX_CALL(mq_receive)(m_mqDescriptor, msg, static_cast(maxMsgSize), nullptr) + .failureReturnValue(ERROR_CODE) + .evaluate(); if (mqCall.has_error()) { @@ -210,4 +213,4 @@ expected MessageQueue::receiveVerification(not_n } } // namespace iox -#endif \ No newline at end of file +#endif diff --git a/iceoryx_hoofs/posix/ipc/include/iox/detail/unix_domain_socket.inl b/iceoryx_hoofs/posix/ipc/include/iox/detail/unix_domain_socket.inl index 21dc4636b7..eed222f3d9 100644 --- a/iceoryx_hoofs/posix/ipc/include/iox/detail/unix_domain_socket.inl +++ b/iceoryx_hoofs/posix/ipc/include/iox/detail/unix_domain_socket.inl @@ -53,7 +53,7 @@ expected UnixDomainSocket::timedSendImpl(not_null(msgSizeToSend), 0, nullptr, 0) .failureReturnValue(ERROR_CODE) .evaluate(); @@ -85,7 +85,7 @@ expected UnixDomainSocket::timedReceiveImpl( return err(errnoToEnum(setsockoptCall.error().errnum)); } - auto recvCall = IOX_POSIX_CALL(iox_recvfrom)(m_sockfd, msg, maxMsgSize, 0, nullptr, nullptr) + auto recvCall = IOX_POSIX_CALL(iox_recvfrom)(m_sockfd, msg, static_cast(maxMsgSize), 0, nullptr, nullptr) .failureReturnValue(ERROR_CODE) .suppressErrorMessagesForErrnos(EAGAIN, EWOULDBLOCK) .evaluate(); diff --git a/iceoryx_hoofs/posix/ipc/include/iox/named_pipe.hpp b/iceoryx_hoofs/posix/ipc/include/iox/named_pipe.hpp index 6517654751..123b35e799 100644 --- a/iceoryx_hoofs/posix/ipc/include/iox/named_pipe.hpp +++ b/iceoryx_hoofs/posix/ipc/include/iox/named_pipe.hpp @@ -213,7 +213,7 @@ class NamedPipeBuilder IOX_BUILDER_PARAMETER(PosixIpcChannelSide, channelSide, PosixIpcChannelSide::CLIENT) /// @brief Defines the max message size of the named pipe - IOX_BUILDER_PARAMETER(size_t, maxMsgSize, NamedPipe::MAX_MESSAGE_SIZE) + IOX_BUILDER_PARAMETER(uint64_t, maxMsgSize, NamedPipe::MAX_MESSAGE_SIZE) /// @brief Defines the max number of messages for the named pipe. IOX_BUILDER_PARAMETER(uint64_t, maxMsgNumber, NamedPipe::MAX_NUMBER_OF_MESSAGES) diff --git a/iceoryx_hoofs/posix/ipc/source/posix_memory_map.cpp b/iceoryx_hoofs/posix/ipc/source/posix_memory_map.cpp index c1e05e23dd..27c6500848 100644 --- a/iceoryx_hoofs/posix/ipc/source/posix_memory_map.cpp +++ b/iceoryx_hoofs/posix/ipc/source/posix_memory_map.cpp @@ -31,7 +31,7 @@ expected PosixMemoryMapBuilder::create() no // AXIVION Next Construct AutosarC++19_03-A5.2.3, CertC++-EXP55 : Incompatibility with POSIX definition of mmap // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) low-level memory management auto result = IOX_POSIX_CALL(mmap)(const_cast(m_baseAddressHint), - m_length, + static_cast(m_length), convertToProtFlags(m_accessMode), static_cast(m_flags), m_fileDescriptor, @@ -176,7 +176,8 @@ bool PosixMemoryMap::destroy() noexcept { if (m_baseAddress != nullptr) { - auto unmapResult = IOX_POSIX_CALL(munmap)(m_baseAddress, m_length).failureReturnValue(-1).evaluate(); + auto unmapResult = + IOX_POSIX_CALL(munmap)(m_baseAddress, static_cast(m_length)).failureReturnValue(-1).evaluate(); m_baseAddress = nullptr; m_length = 0U; diff --git a/iceoryx_hoofs/posix/ipc/source/posix_shared_memory.cpp b/iceoryx_hoofs/posix/ipc/source/posix_shared_memory.cpp index 0d4c0022b6..84a25e3c6d 100644 --- a/iceoryx_hoofs/posix/ipc/source/posix_shared_memory.cpp +++ b/iceoryx_hoofs/posix/ipc/source/posix_shared_memory.cpp @@ -129,7 +129,7 @@ expected PosixSharedMemoryBuilder::cr if (hasOwnership) { - auto result = IOX_POSIX_CALL(iox_ftruncate)(sharedMemoryFileHandle, static_cast(m_size)) + auto result = IOX_POSIX_CALL(iox_ftruncate)(sharedMemoryFileHandle, static_cast(m_size)) .failureReturnValue(PosixSharedMemory::INVALID_HANDLE) .evaluate(); if (result.has_error()) diff --git a/iceoryx_hoofs/posix/ipc/source/posix_shared_memory_object.cpp b/iceoryx_hoofs/posix/ipc/source/posix_shared_memory_object.cpp index 836c33a036..1cf72e2c60 100644 --- a/iceoryx_hoofs/posix/ipc/source/posix_shared_memory_object.cpp +++ b/iceoryx_hoofs/posix/ipc/source/posix_shared_memory_object.cpp @@ -163,7 +163,7 @@ expected PosixSharedMemor (m_baseAddressHint) ? *m_baseAddressHint : nullptr, m_permissions.value())); - memset(memoryMap->getBaseAddress(), 0, m_memorySizeInBytes); + memset(memoryMap->getBaseAddress(), 0, static_cast(m_memorySizeInBytes)); } IOX_LOG(DEBUG, "Acquired " << m_memorySizeInBytes << " bytes successfully in the shared memory [" << m_name << "]"); diff --git a/iceoryx_hoofs/posix/ipc/source/unix_domain_socket.cpp b/iceoryx_hoofs/posix/ipc/source/unix_domain_socket.cpp index 3090a3b5d0..74320da023 100644 --- a/iceoryx_hoofs/posix/ipc/source/unix_domain_socket.cpp +++ b/iceoryx_hoofs/posix/ipc/source/unix_domain_socket.cpp @@ -75,7 +75,8 @@ expected UnixDomainSocketBuilderNoPathPr { return err(PosixIpcChannelError::INVALID_CHANNEL_NAME); } - strncpy(&(sockAddr.sun_path[0]), m_name.c_str(), m_name.size()); + auto nameSize = m_name.size(); + strncpy(&(sockAddr.sun_path[0]), m_name.c_str(), static_cast(nameSize)); // the mask will be applied to the permissions, we only allow users and group members to have read and write access // the system call always succeeds, no need to check for errors diff --git a/iceoryx_hoofs/test/moduletests/test_cli_command_line_common.hpp b/iceoryx_hoofs/test/moduletests/test_cli_command_line_common.hpp index 9c78b4512a..2262de0611 100644 --- a/iceoryx_hoofs/test/moduletests/test_cli_command_line_common.hpp +++ b/iceoryx_hoofs/test/moduletests/test_cli_command_line_common.hpp @@ -30,10 +30,10 @@ struct CmdArgs explicit CmdArgs(const std::vector& arguments) : argc{static_cast(arguments.size())} - , argv{new char*[static_cast(argc)]} + , argv{new char*[static_cast(argc)]} { contents = std::make_unique>(arguments); - for (uint64_t i = 0; i < static_cast(argc); ++i) + for (size_t i = 0; i < static_cast(argc); ++i) { // NOLINTJUSTIFICATION required for test // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) diff --git a/iceoryx_hoofs/test/moduletests/test_container_fixed_position_container.cpp b/iceoryx_hoofs/test/moduletests/test_container_fixed_position_container.cpp index bba82bb50d..9de51449ee 100644 --- a/iceoryx_hoofs/test/moduletests/test_container_fixed_position_container.cpp +++ b/iceoryx_hoofs/test/moduletests/test_container_fixed_position_container.cpp @@ -2455,7 +2455,7 @@ TEST_F(FixedPositionContainer_test, PartiallyFilledUpContainerCallsDestructorOnE } } - uint64_t i = 0; + size_t i = 0; for (const auto value : stats.dTorOrder) { EXPECT_THAT(value, Eq(expected_values[i])); @@ -2586,7 +2586,7 @@ TEST_F(FixedPositionContainer_test, ClearAfterPartiallyFillingContainerUpCallsDe } } - uint64_t i = 0; + size_t i = 0; for (const auto value : stats.dTorOrder) { EXPECT_THAT(value, Eq(expected_values[i])); diff --git a/iceoryx_hoofs/test/moduletests/test_container_vector.cpp b/iceoryx_hoofs/test/moduletests/test_container_vector.cpp index ab4a6c342c..d694e1cc41 100644 --- a/iceoryx_hoofs/test/moduletests/test_container_vector.cpp +++ b/iceoryx_hoofs/test/moduletests/test_container_vector.cpp @@ -498,7 +498,7 @@ TEST_F(vector_test, ReverseDestructionOrderInCopyAssignment) EXPECT_THAT(stats.dTor, Eq(VECTOR_CAPACITY)); ASSERT_THAT(stats.dTorOrder.size(), Eq(VECTOR_CAPACITY)); - for (uint64_t i{0}; i < VECTOR_CAPACITY; ++i) + for (size_t i{0}; i < VECTOR_CAPACITY; ++i) { EXPECT_THAT(stats.dTorOrder[i], Eq(VECTOR_CAPACITY - 1 - i)); } @@ -518,7 +518,7 @@ TEST_F(vector_test, ReverseDestructionOrderInMoveAssignment) EXPECT_THAT(stats.dTor, Eq(VECTOR_CAPACITY)); ASSERT_THAT(stats.dTorOrder.size(), Eq(VECTOR_CAPACITY)); - for (uint64_t i{0}; i < VECTOR_CAPACITY; ++i) + for (size_t i{0}; i < VECTOR_CAPACITY; ++i) { EXPECT_THAT(stats.dTorOrder[i], Eq(VECTOR_CAPACITY - i)); } @@ -1262,7 +1262,7 @@ TEST_F(vector_test, FullVectorDestroysElementsInReverseOrder) } ASSERT_THAT(stats.dTorOrder.size(), Eq(VECTOR_CAPACITY)); - for (uint64_t i = 0U; i < VECTOR_CAPACITY; ++i) + for (size_t i = 0U; i < VECTOR_CAPACITY; ++i) { EXPECT_THAT(stats.dTorOrder[i], Eq(INDEX_END - i + SOME_OFFSET)); } @@ -1286,7 +1286,7 @@ TEST_F(vector_test, PartiallyFullVectorDestroysElementsInReverseOrder) } ASSERT_THAT(stats.dTorOrder.size(), Eq(VECTOR_SIZE)); - for (uint64_t i = 0U; i < VECTOR_SIZE; ++i) + for (size_t i = 0U; i < VECTOR_SIZE; ++i) { EXPECT_THAT(stats.dTorOrder[i], Eq(INDEX_END - i + SOME_OFFSET)); } diff --git a/iceoryx_hoofs/test/moduletests/test_posix_ipc_unix_domain_sockets.cpp b/iceoryx_hoofs/test/moduletests/test_posix_ipc_unix_domain_sockets.cpp index 466ae2bfab..45d661362f 100644 --- a/iceoryx_hoofs/test/moduletests/test_posix_ipc_unix_domain_sockets.cpp +++ b/iceoryx_hoofs/test/moduletests/test_posix_ipc_unix_domain_sockets.cpp @@ -87,7 +87,8 @@ class UnixDomainSocket_test : public Test memset(&sockAddr, 0, sizeof(sockAddr)); sockAddr.sun_family = AF_LOCAL; - strncpy(&(sockAddr.sun_path[0]), name.c_str(), name.size()); + auto nameSize = name.size(); + strncpy(&(sockAddr.sun_path[0]), name.c_str(), static_cast(nameSize)); IOX_POSIX_CALL(iox_socket) (AF_LOCAL, SOCK_DGRAM, 0) diff --git a/iceoryx_hoofs/test/moduletests/test_utility_std_string_support.cpp b/iceoryx_hoofs/test/moduletests/test_utility_std_string_support.cpp index ae111a541b..e88ee2ba35 100644 --- a/iceoryx_hoofs/test/moduletests/test_utility_std_string_support.cpp +++ b/iceoryx_hoofs/test/moduletests/test_utility_std_string_support.cpp @@ -543,7 +543,7 @@ TYPED_TEST(StdString_test, AppendStdStringContainingNullWorks) sut.append(TruncateToCapacity, testStdString); EXPECT_THAT(sut.capacity(), Eq(RESULT_CAPACITY)); EXPECT_THAT(sut.size(), Eq(7U)); - EXPECT_THAT(std::memcmp(sut.c_str(), expectedString.c_str(), sut.size()), Eq(0)); + EXPECT_THAT(std::memcmp(sut.c_str(), expectedString.c_str(), static_cast(sut.size())), Eq(0)); } TYPED_TEST(StdString_test, FindStdStringInEmptyStringFails) diff --git a/iceoryx_hoofs/test/moduletests/test_vocabulary_semantic_string.cpp b/iceoryx_hoofs/test/moduletests/test_vocabulary_semantic_string.cpp index 4309422fed..76e4e0bad0 100644 --- a/iceoryx_hoofs/test/moduletests/test_vocabulary_semantic_string.cpp +++ b/iceoryx_hoofs/test/moduletests/test_vocabulary_semantic_string.cpp @@ -500,7 +500,7 @@ TYPED_TEST(SemanticString_test, InsertValidContentToValidStringWorks) { for (auto& add_value : TestValues::VALID_VALUES) { - for (uint64_t insert_position = 0; insert_position < value.size(); ++insert_position) + for (size_t insert_position = 0; insert_position < value.size(); ++insert_position) { auto sut = SutType::create(string(TruncateToCapacity, value.c_str())); ASSERT_THAT(sut.has_error(), Eq(false)); diff --git a/iceoryx_hoofs/test/moduletests/test_vocabulary_string_concatenate_append_and_insert.cpp b/iceoryx_hoofs/test/moduletests/test_vocabulary_string_concatenate_append_and_insert.cpp index 26e78672ed..43ad950a6b 100644 --- a/iceoryx_hoofs/test/moduletests/test_vocabulary_string_concatenate_append_and_insert.cpp +++ b/iceoryx_hoofs/test/moduletests/test_vocabulary_string_concatenate_append_and_insert.cpp @@ -95,9 +95,9 @@ TYPED_TEST(stringTyped_test, ConcatenateThreeStringsWorks) string testString2("YOD"); auto testString3 = concatenate(testString2, this->testSubject, testString1); - std::string cmpString = std::string(testString2.c_str(), testString2.size()) - + std::string(this->testSubject.c_str(), this->testSubject.size()) - + std::string(testString1.c_str(), testString1.size()); + std::string cmpString = std::string(testString2.c_str(), static_cast(testString2.size())) + + std::string(this->testSubject.c_str(), static_cast(this->testSubject.size())) + + std::string(testString1.c_str(), static_cast(testString1.size())); EXPECT_THAT(testString3.capacity(), Eq(3U * STRINGCAP + 2U)); EXPECT_THAT(testString3.size(), Eq(cmpString.size())); EXPECT_THAT(testString3.c_str(), StrEq(cmpString)); @@ -566,7 +566,7 @@ TYPED_TEST(stringTyped_test, AppendStringContainingNullWorks) sut.append(TruncateToCapacity, testCxxString); EXPECT_THAT(sut.capacity(), Eq(RESULT_CAPACITY)); EXPECT_THAT(sut.size(), Eq(7U)); - EXPECT_THAT(std::memcmp(sut.c_str(), expectedString.c_str(), sut.size()), Eq(0)); + EXPECT_THAT(std::memcmp(sut.c_str(), expectedString.c_str(), static_cast(sut.size())), Eq(0)); } /// @note string& append(TruncateToCapacity_t, char c) noexcept diff --git a/iceoryx_hoofs/test/moduletests/test_vocabulary_string_ctor_and_assign.cpp b/iceoryx_hoofs/test/moduletests/test_vocabulary_string_ctor_and_assign.cpp index 4ce0d48f64..4c1162b619 100644 --- a/iceoryx_hoofs/test/moduletests/test_vocabulary_string_ctor_and_assign.cpp +++ b/iceoryx_hoofs/test/moduletests/test_vocabulary_string_ctor_and_assign.cpp @@ -171,12 +171,12 @@ TYPED_TEST(stringTyped_test, SelfMoveAssignmentExcluded) { ::testing::Test::RecordProperty("TEST_ID", "0ad45975-b68b-465a-b8c5-83dd8d8290d5"); this->testSubject = "M"; -#if (defined(__GNUC__) && __GNUC__ == 13 && !defined(__clang__)) +#if (defined(__GNUC__) && (__GNUC__ >= 13 || __GNUC__ <= 14) && !defined(__clang__)) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wself-move" #endif this->testSubject = std::move(this->testSubject); -#if (defined(__GNUC__) && __GNUC__ == 13 && !defined(__clang__)) +#if (defined(__GNUC__) && (__GNUC__ >= 13 || __GNUC__ <= 14) == 13 && !defined(__clang__)) #pragma GCC diagnostic pop #endif EXPECT_THAT(this->testSubject.size(), Eq(1U)); diff --git a/iceoryx_hoofs/test/stresstests/test_mpmc_lockfree_queue_stresstest.cpp b/iceoryx_hoofs/test/stresstests/test_mpmc_lockfree_queue_stresstest.cpp index fb70d307c3..d21f6f1c26 100644 --- a/iceoryx_hoofs/test/stresstests/test_mpmc_lockfree_queue_stresstest.cpp +++ b/iceoryx_hoofs/test/stresstests/test_mpmc_lockfree_queue_stresstest.cpp @@ -80,7 +80,7 @@ void consume( bool error = false; - std::vector lastCount(maxId + 1, 0); + std::vector lastCount(static_cast(maxId) + 1U, 0); while (run || !queue.empty()) { @@ -88,16 +88,16 @@ void consume( if (popped.has_value()) { auto& value = popped.value(); - if (lastCount[value.id] + 1 != value.count) + if (lastCount[static_cast(value.id)] + 1 != value.count) { error = true; } - lastCount[value.id] = value.count; + lastCount[static_cast(value.id)] = value.count; } } - for (uint64_t i = 1; i <= maxId; ++i) + for (size_t i = 1; i <= maxId; ++i) { if (lastCount[i] != expectedFinalCount) { @@ -150,7 +150,7 @@ bool isStrictlyMonotonic(std::list& list) return true; } - size_t prev = iter->count; + auto prev = iter->count; iter++; while (iter != list.end()) @@ -171,12 +171,12 @@ bool isComplete(std::list& list1, std::list& list2, size_t finalCoun std::vector count(finalCount + 1); for (auto& data : list1) { - count[data.count]++; + count[static_cast(data.count)]++; } for (auto& data : list2) { - count[data.count]++; + count[static_cast(data.count)]++; } for (size_t i = 1; i <= finalCount; ++i) @@ -196,7 +196,7 @@ bool checkTwoConsumerResult(std::list& consumed1, uint64_t expectedFinalCount, uint64_t maxId) { - std::vector> consumed(maxId + 1U); + std::vector> consumed(static_cast(maxId) + 1U); for (uint64_t id = 1; id <= maxId; ++id) { @@ -209,7 +209,7 @@ bool checkTwoConsumerResult(std::list& consumed1, return false; } - if (!isComplete(filtered1, filtered2, expectedFinalCount)) + if (!isComplete(filtered1, filtered2, static_cast(expectedFinalCount))) { IOX_LOG(INFO, "id " << id << " incomplete"); return false; @@ -517,11 +517,11 @@ TYPED_TEST(MpmcLockFreeQueueStressTest, TimedMultiProducerMultiConsumer) } // check whether all elements are there, but there is no specific ordering we can expect - std::vector count(capacity, 0); + std::vector count(static_cast(capacity), 0); auto popped = q.pop(); while (popped.has_value()) { - count[popped.value().count]++; + count[static_cast(popped.value().count)]++; popped = q.pop(); } @@ -585,8 +585,8 @@ TYPED_TEST(MpmcLockFreeQueueStressTest, TimedMultiProducerMultiConsumer0verflow) std::ref(q), id, std::ref(run), - std::ref(overflowCount[id - 1]), - std::ref(itemVec[id - 1]), + std::ref(overflowCount[static_cast(id) - 1]), + std::ref(itemVec[static_cast(id) - 1]), popProbability); } @@ -603,11 +603,11 @@ TYPED_TEST(MpmcLockFreeQueueStressTest, TimedMultiProducerMultiConsumer0verflow) // check whether all elements are there, but there is no specific ordering we can expect // items are either in the local lists or the queue, in total we expect each count numThreads times - std::vector count(capacity, 0U); + std::vector count(static_cast(capacity), 0U); auto popped = q.pop(); while (popped.has_value()) { - count[popped.value().count]++; + count[static_cast(popped.value().count)]++; popped = q.pop(); } @@ -616,14 +616,14 @@ TYPED_TEST(MpmcLockFreeQueueStressTest, TimedMultiProducerMultiConsumer0verflow) { for (auto& item : items) { - count[item.count]++; + count[static_cast(item.count)]++; } } // we expect at least one overflow in the test (since the queue is full in the beginning) // we cannot expect one overflow in each thread due to thread scheduling auto numOverflows = std::accumulate(overflowCount.begin(), overflowCount.end(), 0ULL); - EXPECT_GT(numOverflows, 0LL); + EXPECT_GT(numOverflows, 0ULL); bool testResult = true; for (size_t i = 0; i < capacity; ++i) diff --git a/iceoryx_hoofs/test/stresstests/test_mpmc_resizeable_lockfree_queue_stresstest.cpp b/iceoryx_hoofs/test/stresstests/test_mpmc_resizeable_lockfree_queue_stresstest.cpp index 198eee7567..8af8784a4a 100644 --- a/iceoryx_hoofs/test/stresstests/test_mpmc_resizeable_lockfree_queue_stresstest.cpp +++ b/iceoryx_hoofs/test/stresstests/test_mpmc_resizeable_lockfree_queue_stresstest.cpp @@ -65,7 +65,7 @@ void producePeriodic(Queue& queue, const uint32_t id, CountArray& producedCount, { if (queue.tryPush(d)) { - producedCount[d.count].fetch_add(1U, std::memory_order_relaxed); + producedCount[static_cast(d.count)].fetch_add(1U, std::memory_order_relaxed); d.count = (d.count + 1U) % n; } } @@ -83,7 +83,7 @@ void consume(Queue& queue, CountArray& consumedCount, iox::concurrent::Atomic(value.count)].fetch_add(1U, std::memory_order_relaxed); } } } @@ -305,7 +305,7 @@ void changeCapacity(Queue& queue, incrementK = false; } - if (queue.setCapacity(capacities[static_cast(k)], removeHandler)) + if (queue.setCapacity(capacities[static_cast(k)], removeHandler)) { ++numChanges; } @@ -427,7 +427,7 @@ TYPED_TEST(MpmcResizeableLockFreeQueueStressTest, MultiProducerMultiConsumerComp CountArray consumedCount(cycleLength); // cannot be done with the vector ctor for atomics - for (uint64_t i = 0; i < cycleLength; ++i) + for (size_t i = 0; i < cycleLength; ++i) { producedCount[i].store(0U, std::memory_order_relaxed); consumedCount[i].store(0U, std::memory_order_relaxed); @@ -465,11 +465,11 @@ TYPED_TEST(MpmcResizeableLockFreeQueueStressTest, MultiProducerMultiConsumerComp while (const auto popped = queue.pop()) { const auto& value = popped.value(); - consumedCount[value.count].fetch_add(1U, std::memory_order_relaxed); + consumedCount[static_cast(value.count)].fetch_add(1U, std::memory_order_relaxed); } // verify counts - for (uint64_t i = 0; i < cycleLength; ++i) + for (size_t i = 0; i < cycleLength; ++i) { EXPECT_EQ(producedCount[i].load(), consumedCount[i].load()); } @@ -575,11 +575,11 @@ TYPED_TEST(MpmcResizeableLockFreeQueueStressTest, HybridMultiProducerMultiConsum } // check whether all elements are there, but there is no specific ordering we can expect - std::vector count(capacity, 0); + std::vector count(static_cast(capacity), 0); auto popped = q.pop(); while (popped.has_value()) { - count[popped.value().count]++; + count[static_cast(popped.value().count)]++; popped = q.pop(); } @@ -667,12 +667,12 @@ TYPED_TEST(MpmcResizeableLockFreeQueueStressTest, HybridMultiProducerMultiConsum // items are either in the local lists or the queue, in total we expect each count numThreads times // and for each count each id exactly once - std::vector> count(capacity, std::vector(numThreads + 1, 0)); + std::vector> count(static_cast(capacity), std::vector(numThreads + 1, 0)); auto popped = q.pop(); while (popped.has_value()) { const auto& value = popped.value(); - count[value.count][value.id]++; + count[static_cast(value.count)][value.id]++; popped = q.pop(); } @@ -681,7 +681,7 @@ TYPED_TEST(MpmcResizeableLockFreeQueueStressTest, HybridMultiProducerMultiConsum { for (auto& item : items) { - count[item.count][item.id]++; + count[static_cast(item.count)][item.id]++; } } @@ -787,12 +787,12 @@ TYPED_TEST(MpmcResizeableLockFreeQueueStressTest, HybridMultiProducerMultiConsum // items are either in the local lists or the queue, in total we expect each count numThreads times // and for each count each id exactly once - std::vector> count(capacity, std::vector(numThreads + 1, 0)); + std::vector> count(static_cast(capacity), std::vector(numThreads + 1, 0)); auto popped = q.pop(); while (popped.has_value()) { const auto& value = popped.value(); - count[value.count][value.id]++; + count[static_cast(value.count)][value.id]++; popped = q.pop(); } @@ -801,17 +801,17 @@ TYPED_TEST(MpmcResizeableLockFreeQueueStressTest, HybridMultiProducerMultiConsum { for (auto& item : items) { - count[item.count][item.id]++; + count[static_cast(item.count)][item.id]++; } } bool testResult = true; - for (uint64_t i = 0; i < capacity; ++i) + for (size_t i = 0; i < capacity; ++i) { // we expect each data item exactly numThreads + 1 times, // the extra one is for the initially full queue // and each count appears for all ids exactly ones - for (uint32_t j = 0; j <= numThreads; ++j) + for (size_t j = 0; j <= numThreads; ++j) { if (count[i][j] != 1) { diff --git a/iceoryx_hoofs/utility/include/iox/detail/serialization.inl b/iceoryx_hoofs/utility/include/iox/detail/serialization.inl index 7c8ee96c55..46f0f2213b 100644 --- a/iceoryx_hoofs/utility/include/iox/detail/serialization.inl +++ b/iceoryx_hoofs/utility/include/iox/detail/serialization.inl @@ -107,13 +107,13 @@ inline bool Serialization::deserialize(const std::string& serializedString, T& t inline bool Serialization::removeFirstEntry(std::string& firstEntry, std::string& remainder) noexcept { - uint64_t pos = remainder.find_first_of(SEPARATOR); + auto pos = remainder.find_first_of(SEPARATOR); if (pos == std::string::npos) { return false; } - auto result = convert::from_string(remainder.substr(0, pos).c_str()); + auto result = convert::from_string(remainder.substr(0U, pos).c_str()); if (!result.has_value()) { diff --git a/iceoryx_hoofs/utility/include/iox/detail/std_string_support.inl b/iceoryx_hoofs/utility/include/iox/detail/std_string_support.inl index ea5c5aba5d..95106d03b7 100644 --- a/iceoryx_hoofs/utility/include/iox/detail/std_string_support.inl +++ b/iceoryx_hoofs/utility/include/iox/detail/std_string_support.inl @@ -24,7 +24,7 @@ namespace iox template inline std::string FromImpl, std::string>::fromImpl(const string& value) noexcept { - return std::string(value.c_str(), value.size()); + return std::string(value.c_str(), static_cast(value.size())); } template diff --git a/iceoryx_hoofs/vocabulary/include/iox/detail/string.inl b/iceoryx_hoofs/vocabulary/include/iox/detail/string.inl index 4ed91aa090..4c96ca7b08 100644 --- a/iceoryx_hoofs/vocabulary/include/iox/detail/string.inl +++ b/iceoryx_hoofs/vocabulary/include/iox/detail/string.inl @@ -147,7 +147,7 @@ inline string::string(TruncateToCapacity_t, const char* const other, c } else { - std::memcpy(m_rawstring, other, count); + std::memcpy(m_rawstring, other, static_cast(count)); m_rawstring[count] = '\0'; m_rawstringSize = count; } @@ -187,7 +187,7 @@ inline string& string::operator=(const char (&rhs)[N]) noexc #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Warray-bounds" #endif - std::memcpy(m_rawstring, rhs, m_rawstringSize); + std::memcpy(m_rawstring, rhs, static_cast(m_rawstringSize)); #if (defined(__GNUC__) && (__GNUC__ == 8)) && (__GNUC_MINOR__ >= 3) #pragma GCC diagnostic pop #endif @@ -234,7 +234,7 @@ inline bool string::unsafe_assign(const char* const str) noexcept << ") of the fixed string."); return false; } - std::memcpy(m_rawstring, str, strSize); + std::memcpy(m_rawstring, str, static_cast(strSize)); m_rawstring[strSize] = '\0'; m_rawstringSize = strSize; return true; @@ -264,7 +264,8 @@ template inline IsStringOrCharArray string::compare(const T& other) const noexcept { const uint64_t otherSize{internal::GetSize::call(other)}; - const auto result = memcmp(c_str(), internal::GetData::call(other), std::min(m_rawstringSize, otherSize)); + const auto result = + memcmp(c_str(), internal::GetData::call(other), static_cast(std::min(m_rawstringSize, otherSize))); if (result == 0) { if (m_rawstringSize < otherSize) @@ -330,7 +331,7 @@ inline string& string::copy(const string& rhs) noexcept static_assert(N <= Capacity, "Assignment failed. The capacity of the given fixed string is larger than the capacity of this."); const uint64_t strSize{rhs.size()}; - std::memcpy(m_rawstring, rhs.c_str(), strSize); + std::memcpy(m_rawstring, rhs.c_str(), static_cast(strSize)); m_rawstring[strSize] = '\0'; m_rawstringSize = strSize; return *this; @@ -344,7 +345,7 @@ inline string& string::move(string&& rhs) noexcept static_assert(N <= Capacity, "Assignment failed. The capacity of the given fixed string is larger than the capacity of this."); const uint64_t strSize{rhs.size()}; - std::memcpy(m_rawstring, rhs.c_str(), strSize); + std::memcpy(m_rawstring, rhs.c_str(), static_cast(strSize)); m_rawstring[strSize] = '\0'; m_rawstringSize = strSize; rhs.clear(); @@ -379,8 +380,8 @@ concatenate(const T1& str1, const T2& str2) noexcept uint64_t size2{internal::GetSize::call(str2)}; using NewStringType = string::value>; NewStringType newString; - std::memcpy(newString.m_rawstring, internal::GetData::call(str1), size1); - std::memcpy(&newString.m_rawstring[size1], internal::GetData::call(str2), size2); + std::memcpy(newString.m_rawstring, internal::GetData::call(str1), static_cast(size1)); + std::memcpy(&newString.m_rawstring[size1], internal::GetData::call(str2), static_cast(size2)); newString.m_rawstring[size1 + size2] = '\0'; newString.m_rawstringSize = size1 + size2; @@ -417,7 +418,7 @@ inline IsStringOrCharArrayOrChar string::unsafe_append(const return false; } - std::memcpy(&(m_rawstring[m_rawstringSize]), tData, clampedTSize); + std::memcpy(&(m_rawstring[m_rawstringSize]), tData, static_cast(clampedTSize)); m_rawstringSize += clampedTSize; m_rawstring[m_rawstringSize] = '\0'; return true; @@ -434,7 +435,7 @@ inline IsStringOrCharArrayOrChar&> string::append( const char* const tData{internal::GetData::call(str)}; uint64_t const clampedTSize{std::min(Capacity - m_rawstringSize, tSize)}; - std::memcpy(&(m_rawstring[m_rawstringSize]), tData, clampedTSize); + std::memcpy(&(m_rawstring[m_rawstringSize]), tData, static_cast(clampedTSize)); if (tSize > clampedTSize) { IOX_LOG(WARN, @@ -487,8 +488,9 @@ string::insert(const uint64_t pos, const T& str, const uint64_t count) { return false; } - std::memmove(&m_rawstring[pos + count], &m_rawstring[pos], m_rawstringSize - pos); - std::memcpy(&m_rawstring[pos], internal::GetData::call(str), count); + auto number_of_characters_to_move = static_cast(m_rawstringSize) - static_cast(pos); + std::memmove(&m_rawstring[pos + count], &m_rawstring[pos], number_of_characters_to_move); + std::memcpy(&m_rawstring[pos], internal::GetData::call(str), static_cast(count)); m_rawstring[new_size] = '\0'; m_rawstringSize = new_size; @@ -506,7 +508,7 @@ inline optional> string::substr(const uint64_t pos, c const uint64_t length{std::min(count, m_rawstringSize - pos)}; string subString; - std::memcpy(subString.m_rawstring, &m_rawstring[pos], length); + std::memcpy(subString.m_rawstring, &m_rawstring[pos], static_cast(length)); subString.m_rawstring[length] = '\0'; subString.m_rawstringSize = length; return subString; @@ -549,7 +551,7 @@ inline IsStringOrCharArray> string::find_first_o const uint64_t dataSize{internal::GetSize::call(str)}; for (auto p = pos; p < m_rawstringSize; ++p) { - const void* const found{memchr(data, m_rawstring[p], dataSize)}; + const void* const found{memchr(data, m_rawstring[p], static_cast(dataSize))}; if (found != nullptr) { return p; @@ -577,13 +579,13 @@ inline IsStringOrCharArray> string::find_last_of const uint64_t dataSize{internal::GetSize::call(str)}; for (; p > 0U; --p) { - const void* const found{memchr(data, m_rawstring[p], dataSize)}; + const void* const found{memchr(data, m_rawstring[p], static_cast(dataSize))}; if (found != nullptr) { return p; } } - const void* const found{memchr(data, m_rawstring[p], dataSize)}; + const void* const found{memchr(data, m_rawstring[p], static_cast(dataSize))}; if (found != nullptr) { return 0U; diff --git a/iceoryx_posh/experimental/source/node.cpp b/iceoryx_posh/experimental/source/node.cpp index 03d30fdc06..a9057e7118 100644 --- a/iceoryx_posh/experimental/source/node.cpp +++ b/iceoryx_posh/experimental/source/node.cpp @@ -41,7 +41,8 @@ NodeBuilder&& NodeBuilder::domain_id_from_env() && noexcept iox::string<10> domain_id_string; domain_id_string.unsafe_raw_access([](auto* buffer, const auto info) { size_t actual_size_with_null{0}; - auto result = IOX_POSIX_CALL(iox_getenv_s)(&actual_size_with_null, buffer, info.total_size, "IOX_DOMAIN_ID") + auto result = IOX_POSIX_CALL(iox_getenv_s)( + &actual_size_with_null, buffer, static_cast(info.total_size), "IOX_DOMAIN_ID") .failureReturnValue(-1) .evaluate(); if (result.has_error() && result.error().errnum == ERANGE) @@ -134,7 +135,7 @@ Node::Node(const NodeName_t& name, optional&& ipc_interface) noexcept : m_runtime(unique_ptr{ new runtime::PoshRuntimeImpl{make_optional(&name), - {std::move(runtime_interface), std::move(ipc_interface)}}, + {std::move(runtime_interface), std::move(ipc_interface)}}, [&](auto* const rt) { delete rt; }}) { } diff --git a/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/mempool_introspection.inl b/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/mempool_introspection.inl index ce035ff5fd..b7a568b9f3 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/mempool_introspection.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/mempool_introspection.inl @@ -163,7 +163,7 @@ MemPoolIntrospection::copyMemPoolI dst.m_minFreeChunks = src.m_minFreeChunks; dst.m_numChunks = src.m_numChunks; dst.m_chunkSize = src.m_chunkSize; - dst.m_chunkPayloadSize = src.m_chunkSize - static_cast(sizeof(mepoo::ChunkHeader)); + dst.m_chunkPayloadSize = src.m_chunkSize - sizeof(mepoo::ChunkHeader); } } diff --git a/iceoryx_posh/source/roudi/memory/default_roudi_memory.cpp b/iceoryx_posh/source/roudi/memory/default_roudi_memory.cpp index 386e47d077..6c87d3843c 100644 --- a/iceoryx_posh/source/roudi/memory/default_roudi_memory.cpp +++ b/iceoryx_posh/source/roudi/memory/default_roudi_memory.cpp @@ -48,19 +48,17 @@ DefaultRouDiMemory::DefaultRouDiMemory(const IceoryxConfig& config) noexcept mepoo::MePooConfig DefaultRouDiMemory::introspectionMemPoolConfig(const uint32_t chunkCount) const noexcept { - constexpr uint32_t ALIGNMENT{mepoo::MemPool::CHUNK_MEMORY_ALIGNMENT}; + constexpr size_t ALIGNMENT{mepoo::MemPool::CHUNK_MEMORY_ALIGNMENT}; mepoo::MePooConfig mempoolConfig; mempoolConfig.m_mempoolConfig.push_back( - {align(static_cast(sizeof(roudi::MemPoolIntrospectionInfoContainer)), ALIGNMENT), chunkCount}); + {align(sizeof(roudi::MemPoolIntrospectionInfoContainer), ALIGNMENT), chunkCount}); mempoolConfig.m_mempoolConfig.push_back( - {align(static_cast(sizeof(roudi::ProcessIntrospectionFieldTopic)), ALIGNMENT), chunkCount}); + {align(sizeof(roudi::ProcessIntrospectionFieldTopic), ALIGNMENT), chunkCount}); + mempoolConfig.m_mempoolConfig.push_back({align(sizeof(roudi::PortIntrospectionFieldTopic), ALIGNMENT), chunkCount}); mempoolConfig.m_mempoolConfig.push_back( - {align(static_cast(sizeof(roudi::PortIntrospectionFieldTopic)), ALIGNMENT), chunkCount}); + {align(sizeof(roudi::PortThroughputIntrospectionFieldTopic), ALIGNMENT), chunkCount}); mempoolConfig.m_mempoolConfig.push_back( - {align(static_cast(sizeof(roudi::PortThroughputIntrospectionFieldTopic)), ALIGNMENT), chunkCount}); - mempoolConfig.m_mempoolConfig.push_back( - {align(static_cast(sizeof(roudi::SubscriberPortChangingIntrospectionFieldTopic)), ALIGNMENT), - chunkCount}); + {align(sizeof(roudi::SubscriberPortChangingIntrospectionFieldTopic), ALIGNMENT), chunkCount}); mempoolConfig.optimize(); return mempoolConfig; @@ -68,10 +66,9 @@ mepoo::MePooConfig DefaultRouDiMemory::introspectionMemPoolConfig(const uint32_t mepoo::MePooConfig DefaultRouDiMemory::discoveryMemPoolConfig(const uint32_t chunkCount) const noexcept { - constexpr uint32_t ALIGNMENT{mepoo::MemPool::CHUNK_MEMORY_ALIGNMENT}; + constexpr size_t ALIGNMENT{mepoo::MemPool::CHUNK_MEMORY_ALIGNMENT}; mepoo::MePooConfig mempoolConfig; - mempoolConfig.m_mempoolConfig.push_back( - {align(static_cast(sizeof(roudi::ServiceRegistry)), ALIGNMENT), chunkCount}); + mempoolConfig.m_mempoolConfig.push_back({align(sizeof(roudi::ServiceRegistry), ALIGNMENT), chunkCount}); mempoolConfig.optimize(); return mempoolConfig; diff --git a/iceoryx_posh/test/integrationtests/test_posh_mepoo.cpp b/iceoryx_posh/test/integrationtests/test_posh_mepoo.cpp index 4c528934bb..07428bfdf8 100644 --- a/iceoryx_posh/test/integrationtests/test_posh_mepoo.cpp +++ b/iceoryx_posh/test/integrationtests/test_posh_mepoo.cpp @@ -254,7 +254,7 @@ class Mepoo_IntegrationTest : public Test { if (info.m_chunkSize != 0) { - info.m_chunkSize = info.m_chunkSize - static_cast(sizeof(iox::mepoo::ChunkHeader)); + info.m_chunkSize = info.m_chunkSize - sizeof(iox::mepoo::ChunkHeader); } } }); diff --git a/iceoryx_posh/test/mocks/roudi_memory_provider_mock.hpp b/iceoryx_posh/test/mocks/roudi_memory_provider_mock.hpp index cc4caea58e..6a1d0db39b 100644 --- a/iceoryx_posh/test/mocks/roudi_memory_provider_mock.hpp +++ b/iceoryx_posh/test/mocks/roudi_memory_provider_mock.hpp @@ -46,7 +46,7 @@ class MemoryProviderTestImpl : public iox::roudi::MemoryProvider createMemoryMock(size, alignment); } - dummyMemory = iox::alignedAlloc(alignment, size); + dummyMemory = iox::alignedAlloc(static_cast(alignment), static_cast(size)); return iox::ok(dummyMemory); } MOCK_METHOD(void, createMemoryMock, (uint64_t, uint64_t), (noexcept)); diff --git a/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp b/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp index 0152bd535b..d0422bf7e9 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp @@ -456,7 +456,7 @@ void checkUserPayloadNotOverlappingWithUserHeader(const ChunkHeader& sut, const const uint64_t chunkStartAddress{reinterpret_cast(&sut)}; const uint64_t userPayloadStartAddress{reinterpret_cast(sut.userPayload())}; const uint64_t userHeaderSizeAndPadding{ - iox::algorithm::maxVal(userHeaderSize, static_cast(alignof(UserPayloadOffset_t)))}; + iox::algorithm::maxVal(static_cast(userHeaderSize), alignof(UserPayloadOffset_t))}; constexpr uint64_t BACK_OFFSET_SIZE{sizeof(UserPayloadOffset_t)}; const uint64_t expectedRequiredSpace{sizeof(ChunkHeader) + userHeaderSizeAndPadding + BACK_OFFSET_SIZE}; diff --git a/iceoryx_posh/test/moduletests/test_mepoo_chunk_settings.cpp b/iceoryx_posh/test/moduletests/test_mepoo_chunk_settings.cpp index 2a4ca2f4af..0d2cbb026e 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_chunk_settings.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_chunk_settings.cpp @@ -349,8 +349,8 @@ INSTANTIATE_TEST_SUITE_P(ChunkSettings_test, uint64_t expectedChunkSizeWithUserHeader(const PayloadParams& userPayload, uint32_t userHeaderSize) { - const uint32_t userHeaderSizeAndPaddingToBackOffset = - iox::algorithm::maxVal(userHeaderSize, static_cast(alignof(UserPayloadOffset_t))); + const auto userHeaderSizeAndPaddingToBackOffset = + iox::algorithm::maxVal(static_cast(userHeaderSize), alignof(UserPayloadOffset_t)); if (userPayload.alignment <= alignof(UserPayloadOffset_t)) { diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp index 04e9f65a0d..dd073ca655 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp @@ -798,7 +798,7 @@ TYPED_TEST(ChunkDistributor_test, MultipleBlockingQueuesWillBeFilledWhenThereBec std::this_thread::sleep_for(this->BLOCKING_DURATION); EXPECT_THAT(wasChunkDelivered.load(), Eq(false)); - for (uint64_t i = 0U; i < NUMBER_OF_QUEUES; ++i) + for (size_t i = 0U; i < NUMBER_OF_QUEUES; ++i) { auto maybeSharedChunk = queues[i].tryPop(); ASSERT_THAT(maybeSharedChunk.has_value(), Eq(true)); diff --git a/iceoryx_posh/test/moduletests/test_popo_listener.cpp b/iceoryx_posh/test/moduletests/test_popo_listener.cpp index 556d697ad7..92c01b5016 100644 --- a/iceoryx_posh/test/moduletests/test_popo_listener.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_listener.cpp @@ -892,7 +892,7 @@ TIMING_TEST_F(Listener_test, TriggeringAllEventsCallsAllCallbacks, Repeat(5), [& TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0].m_source.load() == &events[0U]); TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0].m_count.load() == 2U); - for (uint64_t i = 1U; i < iox::MAX_NUMBER_OF_EVENTS_PER_LISTENER; ++i) + for (size_t i = 1U; i < iox::MAX_NUMBER_OF_EVENTS_PER_LISTENER; ++i) { TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[i].m_source.load() == &events[i]); TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[i].m_count.load() == 1U); @@ -925,7 +925,7 @@ TIMING_TEST_F(Listener_test, TriggeringAllEventsCallsAllCallbacksOnce, Repeat(5) TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0].m_source.load() == &events[0U]); TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0].m_count.load() == 3U); - for (uint64_t i = 1U; i < iox::MAX_NUMBER_OF_EVENTS_PER_LISTENER; ++i) + for (size_t i = 1U; i < iox::MAX_NUMBER_OF_EVENTS_PER_LISTENER; ++i) { TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[i].m_source.load() == &events[i]); TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[i].m_count.load() == 1U); @@ -984,13 +984,13 @@ TIMING_TEST_F(Listener_test, AttachingMultipleWhileCallbackIsRunningWorks, Repea AttachEvent::doIt(*m_sut, events, SimpleEvent::StoepselBachelorParty); g_triggerCallbackRuntimeInMs = 0U; - for (uint64_t i = 0U; i + 1U < iox::MAX_NUMBER_OF_EVENTS_PER_LISTENER; ++i) + for (size_t i = 0U; i + 1U < iox::MAX_NUMBER_OF_EVENTS_PER_LISTENER; ++i) { events[i].triggerStoepsel(); } std::this_thread::sleep_for(std::chrono::milliseconds(CALLBACK_WAIT_IN_MS / 2U)); - for (uint64_t i = 0U; i + 1U < iox::MAX_NUMBER_OF_EVENTS_PER_LISTENER; ++i) + for (size_t i = 0U; i + 1U < iox::MAX_NUMBER_OF_EVENTS_PER_LISTENER; ++i) { TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[i].m_source.load() == &events[i]); TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[i].m_count.load() == 1U); @@ -1089,7 +1089,7 @@ TIMING_TEST_F(Listener_test, DetachingMultipleWhileCallbackIsRunningWorks, Repea } std::this_thread::sleep_for(std::chrono::milliseconds(CALLBACK_WAIT_IN_MS)); - for (uint64_t i = 0U; i < iox::MAX_NUMBER_OF_EVENTS_PER_LISTENER; ++i) + for (size_t i = 0U; i < iox::MAX_NUMBER_OF_EVENTS_PER_LISTENER; ++i) { TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[i].m_source.load() == nullptr); } diff --git a/iceoryx_posh/testing/include/iceoryx_posh/testing/mocks/chunk_mock.hpp b/iceoryx_posh/testing/include/iceoryx_posh/testing/mocks/chunk_mock.hpp index 3a8a58f4fc..4240e9d7c0 100644 --- a/iceoryx_posh/testing/include/iceoryx_posh/testing/mocks/chunk_mock.hpp +++ b/iceoryx_posh/testing/include/iceoryx_posh/testing/mocks/chunk_mock.hpp @@ -48,9 +48,10 @@ class ChunkMock auto& chunkSettings = chunkSettingsResult.value(); auto chunkSize = chunkSettings.requiredChunkSize(); - m_rawMemory = static_cast(iox::alignedAlloc(alignof(iox::mepoo::ChunkHeader), chunkSize)); + m_rawMemory = + static_cast(iox::alignedAlloc(alignof(iox::mepoo::ChunkHeader), static_cast(chunkSize))); assert(m_rawMemory != nullptr && "Could not get aligned memory"); - memset(m_rawMemory, 0xFF, chunkSize); + memset(m_rawMemory, 0xFF, static_cast(chunkSize)); m_chunkHeader = new (m_rawMemory) iox::mepoo::ChunkHeader(chunkSize, chunkSettings); diff --git a/tools/introspection/source/introspection_app.cpp b/tools/introspection/source/introspection_app.cpp index d938298005..9fe006599d 100644 --- a/tools/introspection/source/introspection_app.cpp +++ b/tools/introspection/source/introspection_app.cpp @@ -280,6 +280,22 @@ void IntrospectionApp::printProcessIntrospectionData(const ProcessIntrospectionF wprintw(pad, "\n"); } +template +constexpr const char* format_uint64_t() noexcept; +template <> +constexpr const char* format_uint64_t() noexcept +{ + return "%*lu%s"; +} +template <> +constexpr const char* format_uint64_t() noexcept +{ + return "%*llu%s"; +} + +template +static constexpr const char* FORMAT_UINT64_T{format_uint64_t()}; + void IntrospectionApp::printMemPoolInfo(const MemPoolIntrospectionInfo& introspectionInfo) { wprintw(pad, "Segment ID: %d\n", introspectionInfo.m_id); @@ -312,12 +328,12 @@ void IntrospectionApp::printMemPoolInfo(const MemPoolIntrospectionInfo& introspe auto& info = introspectionInfo.m_mempoolInfo[i]; if (info.m_numChunks > 0u) { - wprintw(pad, "%*zd |", memPoolWidth, i + 1u); - wprintw(pad, "%*d |", usedchunksWidth, info.m_usedChunks); - wprintw(pad, "%*d |", numchunksWidth, info.m_numChunks); - wprintw(pad, "%*d |", minFreechunksWidth, info.m_minFreeChunks); - wprintw(pad, "%*ld |", chunkSizeWidth, info.m_chunkSize); - wprintw(pad, "%*ld\n", chunkPayloadSizeWidth, info.m_chunkPayloadSize); + wprintw(pad, "%*zu |", memPoolWidth, i + 1u); + wprintw(pad, "%*u |", usedchunksWidth, info.m_usedChunks); + wprintw(pad, "%*u |", numchunksWidth, info.m_numChunks); + wprintw(pad, "%*u |", minFreechunksWidth, info.m_minFreeChunks); + wprintw(pad, FORMAT_UINT64_T, chunkSizeWidth, info.m_chunkSize, " |"); + wprintw(pad, FORMAT_UINT64_T, chunkPayloadSizeWidth, info.m_chunkPayloadSize, "\n"); } } wprintw(pad, "\n"); @@ -576,7 +592,8 @@ IntrospectionApp::composePublisherPortData(const PortIntrospectionFieldTopic* po const PortThroughputIntrospectionFieldTopic* throughputData) { std::vector publisherPortData; - publisherPortData.reserve(portData->m_publisherList.size()); + auto listSize = portData->m_publisherList.size(); + publisherPortData.reserve(static_cast(listSize)); const PortThroughputData dummyThroughputData; @@ -625,7 +642,8 @@ std::vector IntrospectionApp::composeSubscriberPortD const SubscriberPortChangingIntrospectionFieldTopic* subscriberPortChangingData) { std::vector subscriberPortData; - subscriberPortData.reserve(portData->m_subscriberList.size()); + auto listSize = portData->m_subscriberList.size(); + subscriberPortData.reserve(static_cast(listSize)); uint32_t i = 0U; if (portData->m_subscriberList.size() == subscriberPortChangingData->subscriberPortChangingDataList.size())