Skip to content

Commit

Permalink
Merge pull request eclipse-iceoryx#1538 from ApexAI/iox-#1196-activat…
Browse files Browse the repository at this point in the history
…e-clang-tidy-check-on-posix-wrappers

iox-eclipse-iceoryx#1196 activate clang-tidy check on posix wrapper
  • Loading branch information
elfenpiff authored Jul 25, 2022
2 parents d77cb7c + 28200ba commit bfa9770
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 13 deletions.
7 changes: 4 additions & 3 deletions .clang-tidy-diff-scans.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
./iceoryx_hoofs/test/moduletests/test_concurrent_sofi.cpp
./iceoryx_hoofs/test/stresstests/test_stress_sofi.cpp

./iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/*
./iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/*
./iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/shared_memory_object/*
./iceoryx_hoofs/source/posix_wrapper/*
./iceoryx_hoofs/source/posix_wrapper/shared_memory_object/*
./iceoryx_hoofs/test/moduletests/test_allocator.cpp
./iceoryx_hoofs/test/moduletests/test_shared_memory.cpp
./iceoryx_hoofs/test/moduletests/test_shared_memory_object.cpp
./iceoryx_hoofs/test/moduletests/test_posix*

# IMPORTANT:
# after the first # everything is considered a comment, add new files and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SharedMemoryObject
public:
using Builder = SharedMemoryObjectBuilder;

static constexpr void* NO_ADDRESS_HINT = nullptr;
static constexpr const void* const NO_ADDRESS_HINT = nullptr;
SharedMemoryObject(const SharedMemoryObject&) = delete;
SharedMemoryObject& operator=(const SharedMemoryObject&) = delete;
SharedMemoryObject(SharedMemoryObject&&) noexcept = default;
Expand Down
2 changes: 2 additions & 0 deletions iceoryx_hoofs/source/posix_wrapper/message_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ MessageQueue& MessageQueue::operator=(MessageQueue&& other) noexcept
}
CreationPattern_t::operator=(std::move(other));

/// NOLINTJUSTIFICATION iox-#1036 will be fixed with the builder pattern
/// NOLINTNEXTLINE(bugprone-use-after-move,hicpp-invalid-access-moved)
m_name = std::move(other.m_name);
m_attributes = other.m_attributes;
m_mqDescriptor = other.m_mqDescriptor;
Expand Down
17 changes: 14 additions & 3 deletions iceoryx_hoofs/source/posix_wrapper/named_pipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ NamedPipe& NamedPipe::operator=(NamedPipe&& rhs) noexcept
IOX_DISCARD_RESULT(destroy());
CreationPattern_t::operator=(std::move(rhs));

/// NOLINTJUSTIFICATION iox-#1036 will be fixed with the builder pattern
/// NOLINTNEXTLINE(bugprone-use-after-move,hicpp-invalid-access-moved)
m_sharedMemory = std::move(rhs.m_sharedMemory);
m_data = rhs.m_data;
rhs.m_data = nullptr;
Expand All @@ -153,9 +155,18 @@ NamedPipe::~NamedPipe() noexcept
template <typename Prefix>
IpcChannelName_t NamedPipe::convertName(const Prefix& p, const IpcChannelName_t& name) noexcept
{
return IpcChannelName_t(cxx::TruncateToCapacity,
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
cxx::concatenate(p, (name.c_str()[0] == '/') ? *name.substr(1) : name).c_str());
IpcChannelName_t channelName = p;

if (name[0] == '/')
{
name.substr(1).and_then([&](auto& s) { channelName.append(cxx::TruncateToCapacity, s); });
}
else
{
channelName.append(cxx::TruncateToCapacity, name);
}

return channelName;
}

cxx::expected<IpcChannelError> NamedPipe::destroy() noexcept
Expand Down
25 changes: 19 additions & 6 deletions iceoryx_hoofs/source/posix_wrapper/shared_memory_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,22 @@ namespace iox
{
namespace posix
{
constexpr void* SharedMemoryObject::NO_ADDRESS_HINT;
constexpr const void* const SharedMemoryObject::NO_ADDRESS_HINT;
constexpr uint64_t SIGBUS_ERROR_MESSAGE_LENGTH = 1024U + platform::IOX_MAX_SHM_NAME_LENGTH;

/// NOLINTJUSTIFICATION global variables are only accessible from within this compilation unit
/// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)
///
/// NOLINTJUSTIFICATION c array required to print a signal safe error message in memsetSigbusHandler
/// NOLINTNEXTLINE(hicpp-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays)
static char sigbusErrorMessage[SIGBUS_ERROR_MESSAGE_LENGTH];
static std::mutex sigbusHandlerMutex;
/// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)

static void memsetSigbusHandler(int) noexcept
{
auto result = write(STDERR_FILENO, sigbusErrorMessage, strnlen(sigbusErrorMessage, SIGBUS_ERROR_MESSAGE_LENGTH));
auto result =
write(STDERR_FILENO, &sigbusErrorMessage[0], strnlen(&sigbusErrorMessage[0], SIGBUS_ERROR_MESSAGE_LENGTH));
IOX_DISCARD_RESULT(result);
_exit(EXIT_FAILURE);
}
Expand All @@ -52,7 +59,10 @@ cxx::expected<SharedMemoryObject, SharedMemoryObjectError> SharedMemoryObjectBui
auto printErrorDetails = [this] {
LogError() << "Unable to create a shared memory object with the following properties [ name = " << m_name
<< ", sizeInBytes = " << m_memorySizeInBytes << ", access mode = " << asStringLiteral(m_accessMode)
<< ", open mode = " << asStringLiteral(m_openMode) << ", baseAddressHint = "
<< ", open mode = " << asStringLiteral(m_openMode)
<< ", baseAddressHint = "
// NOLINTJUSTIFICATION baseAddressHint printed on failure to make debugging easier as uint64 hex
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
<< ((m_baseAddressHint) ? log::HexFormat(reinterpret_cast<uint64_t>(*m_baseAddressHint))
: log::HexFormat(static_cast<uint64_t>(0U)))
<< ((m_baseAddressHint) ? "" : " (no hint set)")
Expand Down Expand Up @@ -108,8 +118,11 @@ cxx::expected<SharedMemoryObject, SharedMemoryObjectError> SharedMemoryObjectBui
return cxx::error<SharedMemoryObjectError>(SharedMemoryObjectError::INTERNAL_LOGIC_FAILURE);
}

snprintf(
sigbusErrorMessage,
// NOLINTJUSTIFICATION snprintf required to populate char array so that it can be used signal safe in
// a possible signal call
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
IOX_DISCARD_RESULT(snprintf(
&sigbusErrorMessage[0],
SIGBUS_ERROR_MESSAGE_LENGTH,
"While setting the acquired shared memory to zero a fatal SIGBUS signal appeared caused by memset. The "
"shared memory object with the following properties [ name = %s, sizeInBytes = %llu, access mode = %s, "
Expand All @@ -120,7 +133,7 @@ cxx::expected<SharedMemoryObject, SharedMemoryObjectError> SharedMemoryObjectBui
asStringLiteral(m_accessMode),
asStringLiteral(m_openMode),
(m_baseAddressHint) ? *m_baseAddressHint : nullptr,
std::bitset<sizeof(mode_t)>(static_cast<mode_t>(m_permissions)).to_ulong());
std::bitset<sizeof(mode_t)>(static_cast<mode_t>(m_permissions)).to_ulong()));

memset(memoryMap->getBaseAddress(), 0, m_memorySizeInBytes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ TYPED_TEST(SemaphoreInterfaceTest, FailingTimedWaitDoesNotChangeSemaphoreValue)
{
::testing::Test::RecordProperty("TEST_ID", "cb2f5ded-7c04-4e2d-ab41-bbe231a520c7");
constexpr uint64_t NUMBER_OF_DECREMENTS = 4U;
// NOLINTJUSTIFICATION user defined literal no risk of number-letter mixup
// NOLINTNEXTLINE(hicpp-uppercase-literal-suffix,readability-uppercase-literal-suffix)
constexpr iox::units::Duration timeToWait = 2_us;

for (uint64_t i = 0; i < NUMBER_OF_DECREMENTS; ++i)
Expand Down

0 comments on commit bfa9770

Please sign in to comment.