Skip to content

Commit

Permalink
Merge pull request #1793 from ApexAI/iox-1394-fix-autosar-violations-…
Browse files Browse the repository at this point in the history
…in-pointer-repository

iox-#1394 Fix AUTOSAR violations in PointerRepository
  • Loading branch information
FerdinandSpitzschnueffler authored Nov 16, 2022
2 parents 47feaef + c59d94c commit 36cae1d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ constexpr uint64_t MAX_POINTER_REPO_CAPACITY{10000U};
/// id 0 is reserved and allows relative pointers to behave like normal pointers
/// (which is equivalent to measure the offset relative to 0).
template <typename id_t, typename ptr_t, uint64_t CAPACITY = MAX_POINTER_REPO_CAPACITY>
class PointerRepository
class PointerRepository final
{
private:
struct Info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ template <typename id_t, typename ptr_t, uint64_t CAPACITY>
inline cxx::optional<id_t> PointerRepository<id_t, ptr_t, CAPACITY>::registerPtr(const ptr_t ptr,
const uint64_t size) noexcept
{
for (id_t id = 1U; id <= MAX_ID; ++id)
for (id_t id{1U}; id <= MAX_ID; ++id)
{
if (addPointerIfIdIsFree(id, ptr, size))
{
Expand All @@ -60,7 +60,7 @@ inline cxx::optional<id_t> PointerRepository<id_t, ptr_t, CAPACITY>::registerPtr
template <typename id_t, typename ptr_t, uint64_t CAPACITY>
inline bool PointerRepository<id_t, ptr_t, CAPACITY>::unregisterPtr(const id_t id) noexcept
{
if (id <= MAX_ID && id >= MIN_ID)
if ((id <= MAX_ID) && (id >= MIN_ID))
{
if (m_info[id].basePtr != nullptr)
{
Expand All @@ -87,7 +87,7 @@ inline void PointerRepository<id_t, ptr_t, CAPACITY>::unregisterAll() noexcept
template <typename id_t, typename ptr_t, uint64_t CAPACITY>
inline ptr_t PointerRepository<id_t, ptr_t, CAPACITY>::getBasePtr(const id_t id) const noexcept
{
if (id <= MAX_ID && id >= MIN_ID)
if ((id <= MAX_ID) && (id >= MIN_ID))
{
return m_info[id].basePtr;
}
Expand All @@ -102,10 +102,11 @@ inline ptr_t PointerRepository<id_t, ptr_t, CAPACITY>::getBasePtr(const id_t id)
template <typename id_t, typename ptr_t, uint64_t CAPACITY>
inline id_t PointerRepository<id_t, ptr_t, CAPACITY>::searchId(const ptr_t ptr) const noexcept
{
for (id_t id = 1U; id <= m_maxRegistered; ++id)
for (id_t id{1U}; id <= m_maxRegistered; ++id)
{
// return first id where the ptr is in the corresponding interval
if (ptr >= m_info[id].basePtr && ptr <= m_info[id].endPtr)
// AXIVION Next Construct AutosarC++19_03-M5.14.1 : False positive. vector::operator[](index) has no side-effect when index is less than vector size which is guaranteed by PointerRepository design
if ((ptr >= m_info[id].basePtr) && (ptr <= m_info[id].endPtr))
{
return id;
}
Expand All @@ -122,10 +123,11 @@ inline bool PointerRepository<id_t, ptr_t, CAPACITY>::addPointerIfIdIsFree(const
if (m_info[id].basePtr == nullptr)
{
m_info[id].basePtr = ptr;
// AXIVION Next Construct AutosarC++19_03-M5.2.9 : Used for pointer arithmetic with void pointer, uintptr_t is capable of holding a void ptr
// AXIVION Next Construct AutosarC++19_03-A5.2.4 : Cast is needed for pointer arithmetic and casted back
// to the original type
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
m_info[id].endPtr = reinterpret_cast<ptr_t>(reinterpret_cast<uintptr_t>(ptr) + size - 1U);
m_info[id].endPtr = reinterpret_cast<ptr_t>(reinterpret_cast<uintptr_t>(ptr) + (size - 1U));

if (id > m_maxRegistered)
{
Expand Down

0 comments on commit 36cae1d

Please sign in to comment.