diff --git a/iceoryx_dust/source/posix_wrapper/named_pipe.cpp b/iceoryx_dust/source/posix_wrapper/named_pipe.cpp index 76cd248b1f7..e32fbfa63e2 100644 --- a/iceoryx_dust/source/posix_wrapper/named_pipe.cpp +++ b/iceoryx_dust/source/posix_wrapper/named_pipe.cpp @@ -110,7 +110,7 @@ NamedPipe::NamedPipe(const IpcChannelName_t& name, auto allocationResult = m_sharedMemory->allocate(sizeof(NamedPipeData), alignof(NamedPipeData)); if (allocationResult.has_error()) { - std::cerr << "Unable to allocate for named pipe \"" << name << "\"" << std::endl; + std::cerr << "Unable to allocate memory for named pipe \"" << name << "\"" << std::endl; m_isInitialized = false; m_errorValue = IpcChannelError::MEMORY_ALLOCATION_FAILED; return; diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/storable_function.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/storable_function.hpp index 93b701c3c17..a6eb01e00e9 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/storable_function.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/storable_function.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2020 - 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2020 - 2023 by Apex.AI Inc. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -193,6 +193,9 @@ class storable_function> final // m_invoker is initialized with this function and has to work with functors as well // (functors may change due to invocation) static ReturnType invokeFreeFunction(void* callable, Args&&... args) noexcept; + + template + static constexpr void* safeAlign(byte_t* startAddress); }; /// @brief swap two storable functions diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/storable_function.inl b/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/storable_function.inl index 73f3c941979..e0f0ec3b1d0 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/storable_function.inl +++ b/iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/storable_function.inl @@ -172,10 +172,11 @@ inline void swap(storable_function& f, storable_function -void* allocate(byte_t* startAddress) +template +template +inline constexpr void* storable_function>::safeAlign(byte_t* startAddress) { - static_assert(sizeof(T) + alignof(T) - 1 <= Capacity, "type does not fit into storage"); + static_assert(is_storable(), "type does not fit into storage"); // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast, performance-no-int-to-ptr) required for low level pointer alignment uint64_t alignment = alignof(T); uint64_t alignedPosition = cxx::align(reinterpret_cast(startAddress), alignment); @@ -188,7 +189,7 @@ template inline void storable_function>::storeFunctor(const Functor& functor) noexcept { using StoredType = typename std::remove_reference::type; - m_callable = allocate(m_storage); + m_callable = safeAlign(m_storage); // erase the functor type and store as reference to the call in storage new (m_callable) StoredType(functor); @@ -205,7 +206,7 @@ template inline void storable_function>::copy(const storable_function& src, storable_function& dest) noexcept { - dest.m_callable = allocate(dest.m_storage); + dest.m_callable = safeAlign(dest.m_storage); // AXIVION Next Construct AutosarC++19_03-M5.2.8: type erasure - conversion to compatible type const auto obj = static_cast(src.m_callable); @@ -223,7 +224,7 @@ template inline void storable_function>::move(storable_function& src, storable_function& dest) noexcept { - dest.m_callable = allocate(dest.m_storage); + dest.m_callable = safeAlign(dest.m_storage); // AXIVION Next Construct AutosarC++19_03-M5.2.8: type erasure - conversion to compatible type const auto obj = static_cast(src.m_callable); diff --git a/iceoryx_hoofs/memory/include/iox/bump_allocator.hpp b/iceoryx_hoofs/memory/include/iox/bump_allocator.hpp index 15016d6fc58..569875a20c7 100644 --- a/iceoryx_hoofs/memory/include/iox/bump_allocator.hpp +++ b/iceoryx_hoofs/memory/include/iox/bump_allocator.hpp @@ -49,7 +49,7 @@ class BumpAllocator /// @brief allocates on the memory supplied with the ctor /// @param[in] size of the memory to allocate, must be greater than 0 /// @param[in] alignment of the memory to allocate - /// @return returns an expected containing a pointer to the memory if allocation was successful, otherwise + /// @return an expected containing a pointer to the memory if allocation was successful, otherwise /// BumpAllocatorError cxx::expected allocate(const uint64_t size, const uint64_t alignment) noexcept;