Skip to content

Commit

Permalink
iox-eclipse-iceoryx#2301 Fix warnings for 32 bit build
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Aug 22, 2024
1 parent 6180f87 commit 8a95035
Show file tree
Hide file tree
Showing 36 changed files with 146 additions and 133 deletions.
2 changes: 1 addition & 1 deletion iceoryx_binding_c/source/c_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(nameLength));
name[nameLength - 1U] = '\0'; // strncpy doesn't add a null-termination if destination is smaller than source

return instanceName.size();
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_hoofs/cli/source/command_line_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(maxLength) + 1) <= maxLength);
}

bool CommandLineParser::doesOptionNameFitIntoString(const char* option) const noexcept
Expand Down
8 changes: 4 additions & 4 deletions iceoryx_hoofs/container/include/iox/detail/vector.inl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ inline vector<T, Capacity>& vector<T, Capacity>::operator=(const vector& rhs) no

if constexpr (std::is_trivially_copyable<T>::value)
{
std::memcpy(data(), rhs.data(), rhsSize * sizeof(T));
std::memcpy(data(), rhs.data(), static_cast<size_t>(rhsSize) * sizeof(T));
i = rhsSize;
}
else
Expand Down Expand Up @@ -129,7 +129,7 @@ inline vector<T, Capacity>& vector<T, Capacity>::operator=(vector&& rhs) noexcep

if constexpr (std::is_trivially_copyable<T>::value)
{
std::memcpy(data(), rhs.data(), rhsSize * sizeof(T));
std::memcpy(data(), rhs.data(), static_cast<size_t>(rhsSize) * sizeof(T));
i = rhsSize;
}
else
Expand Down Expand Up @@ -220,7 +220,7 @@ inline bool vector<T, Capacity>::emplace(const uint64_t position, Targs&&... arg
if constexpr (std::is_trivial<T>::value)
{
resize(size() + 1U);
const uint64_t dataLen{sizeBeforeEmplace - position};
const size_t dataLen{static_cast<size_t>(sizeBeforeEmplace) - static_cast<size_t>(position)};
std::memmove(data() + position + 1U, data() + position, dataLen * sizeof(T));
at_unchecked(position) = T{std::forward<Targs>(args)...};
}
Expand Down Expand Up @@ -414,7 +414,7 @@ inline bool vector<T, Capacity>::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<size_t>(dataLen) * sizeof(T));
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_hoofs/memory/include/iox/detail/static_storage.inl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ constexpr void* static_storage<Capacity, Align>::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<size_t>(align), static_cast<size_t>(size), m_ptr, space) != nullptr)
{
// fits, ptr was potentially modified to reflect alignment
return m_ptr;
Expand Down
3 changes: 2 additions & 1 deletion iceoryx_hoofs/memory/source/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ void* alignedAlloc(const uint64_t alignment, const uint64_t size) noexcept
// 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<uint64_t>(std::malloc(size + alignment + sizeof(void*) - 1));
auto memory = reinterpret_cast<uint64_t>(
std::malloc(static_cast<size_t>(size) + static_cast<size_t>(alignment) + sizeof(void*) - 1));
if (memory == 0)
{
return nullptr;
Expand Down
8 changes: 6 additions & 2 deletions iceoryx_hoofs/posix/filesystem/source/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(buffer_len))
.failureReturnValue(-1)
.evaluate();

if (!result.has_error())
{
Expand Down Expand Up @@ -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<size_t>(buffer_len))
.failureReturnValue(-1)
.evaluate();

if (!result.has_error())
{
Expand Down
25 changes: 14 additions & 11 deletions iceoryx_hoofs/posix/ipc/include/iox/detail/message_queue.inl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ MessageQueue::timedSendImpl(not_null<const Type*> 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<size_t>(msgSizeToSend), 1U, &timeOut)
.failureReturnValue(ERROR_CODE)
// don't use the suppressErrorMessagesForErrnos method since QNX used EINTR instead of ETIMEDOUT
.ignoreErrnos(TIMEOUT_ERRNO)
Expand Down Expand Up @@ -74,8 +74,9 @@ expected<void, PosixIpcChannelError> MessageQueue::sendImpl(not_null<const Type*
return err(PosixIpcChannelError::MESSAGE_TOO_LONG);
}

auto mqCall =
IOX_POSIX_CALL(mq_send)(m_mqDescriptor, msg, msgSizeToSend, 1U).failureReturnValue(ERROR_CODE).evaluate();
auto mqCall = IOX_POSIX_CALL(mq_send)(m_mqDescriptor, msg, static_cast<size_t>(msgSizeToSend), 1U)
.failureReturnValue(ERROR_CODE)
.evaluate();

if (mqCall.has_error())
{
Expand All @@ -95,11 +96,12 @@ expected<uint64_t, PosixIpcChannelError>
MessageQueue::timedReceiveImpl(not_null<Type*> 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<size_t>(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())
{
Expand All @@ -118,8 +120,9 @@ template <typename Type, MessageQueue::Termination Terminator>
expected<uint64_t, PosixIpcChannelError> MessageQueue::receiveImpl(not_null<Type*> 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<size_t>(maxMsgSize), nullptr)
.failureReturnValue(ERROR_CODE)
.evaluate();

if (mqCall.has_error())
{
Expand Down Expand Up @@ -210,4 +213,4 @@ expected<uint64_t, PosixIpcChannelError> MessageQueue::receiveVerification(not_n
}
} // namespace iox

#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ expected<void, PosixIpcChannelError> UnixDomainSocket::timedSendImpl(not_null<co
{
msgSizeToSend += NULL_TERMINATOR_SIZE;
}
auto sendCall = IOX_POSIX_CALL(iox_sendto)(m_sockfd, msg, msgSizeToSend, 0, nullptr, 0)
auto sendCall = IOX_POSIX_CALL(iox_sendto)(m_sockfd, msg, static_cast<size_t>(msgSizeToSend), 0, nullptr, 0)
.failureReturnValue(ERROR_CODE)
.evaluate();

Expand Down Expand Up @@ -85,7 +85,7 @@ expected<uint64_t, PosixIpcChannelError> 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<size_t>(maxMsgSize), 0, nullptr, nullptr)
.failureReturnValue(ERROR_CODE)
.suppressErrorMessagesForErrnos(EAGAIN, EWOULDBLOCK)
.evaluate();
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_hoofs/posix/ipc/include/iox/named_pipe.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions iceoryx_hoofs/posix/ipc/source/posix_memory_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ expected<PosixMemoryMap, PosixMemoryMapError> 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<void*>(m_baseAddressHint),
m_length,
static_cast<size_t>(m_length),
convertToProtFlags(m_accessMode),
static_cast<int32_t>(m_flags),
m_fileDescriptor,
Expand Down Expand Up @@ -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<size_t>(m_length)).failureReturnValue(-1).evaluate();
m_baseAddress = nullptr;
m_length = 0U;

Expand Down
2 changes: 1 addition & 1 deletion iceoryx_hoofs/posix/ipc/source/posix_shared_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ expected<PosixSharedMemory, PosixSharedMemoryError> PosixSharedMemoryBuilder::cr

if (hasOwnership)
{
auto result = IOX_POSIX_CALL(iox_ftruncate)(sharedMemoryFileHandle, static_cast<int64_t>(m_size))
auto result = IOX_POSIX_CALL(iox_ftruncate)(sharedMemoryFileHandle, static_cast<off_t>(m_size))
.failureReturnValue(PosixSharedMemory::INVALID_HANDLE)
.evaluate();
if (result.has_error())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ expected<PosixSharedMemoryObject, PosixSharedMemoryObjectError> PosixSharedMemor
(m_baseAddressHint) ? *m_baseAddressHint : nullptr,
m_permissions.value()));

memset(memoryMap->getBaseAddress(), 0, m_memorySizeInBytes);
memset(memoryMap->getBaseAddress(), 0, static_cast<size_t>(m_memorySizeInBytes));
}
IOX_LOG(DEBUG,
"Acquired " << m_memorySizeInBytes << " bytes successfully in the shared memory [" << m_name << "]");
Expand Down
3 changes: 2 additions & 1 deletion iceoryx_hoofs/posix/ipc/source/unix_domain_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ expected<UnixDomainSocket, PosixIpcChannelError> 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<size_t>(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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ struct CmdArgs

explicit CmdArgs(const std::vector<std::string>& arguments)
: argc{static_cast<int>(arguments.size())}
, argv{new char*[static_cast<uint64_t>(argc)]}
, argv{new char*[static_cast<size_t>(argc)]}
{
contents = std::make_unique<std::vector<std::string>>(arguments);
for (uint64_t i = 0; i < static_cast<uint64_t>(argc); ++i)
for (size_t i = 0; i < static_cast<size_t>(argc); ++i)
{
// NOLINTJUSTIFICATION required for test
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
Expand Down Expand Up @@ -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]));
Expand Down
8 changes: 4 additions & 4 deletions iceoryx_hoofs/test/moduletests/test_container_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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));
}
Expand Down Expand Up @@ -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));
}
Expand All @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(nameSize));

IOX_POSIX_CALL(iox_socket)
(AF_LOCAL, SOCK_DGRAM, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(sut.size())), Eq(0));
}

TYPED_TEST(StdString_test, FindStdStringInEmptyStringFails)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ TYPED_TEST(SemanticString_test, InsertValidContentToValidStringWorks)
{
for (auto& add_value : TestValues<SutType>::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<SutType::capacity()>(TruncateToCapacity, value.c_str()));
ASSERT_THAT(sut.has_error(), Eq(false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ TYPED_TEST(stringTyped_test, ConcatenateThreeStringsWorks)
string<STRINGCAP + 2U> 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<size_t>(testString2.size()))
+ std::string(this->testSubject.c_str(), static_cast<size_t>(this->testSubject.size()))
+ std::string(testString1.c_str(), static_cast<size_t>(testString1.size()));
EXPECT_THAT(testString3.capacity(), Eq(3U * STRINGCAP + 2U));
EXPECT_THAT(testString3.size(), Eq(cmpString.size()));
EXPECT_THAT(testString3.c_str(), StrEq(cmpString));
Expand Down Expand Up @@ -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<size_t>(sut.size())), Eq(0));
}

/// @note string& append(TruncateToCapacity_t, char c) noexcept
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Loading

0 comments on commit 8a95035

Please sign in to comment.