Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1614 Use UninitializedArray in iceoryx_hoofs/posi…
Browse files Browse the repository at this point in the history
…x_wrapper/

Signed-off-by: Marika Lehmann <marika.lehmann@apex.ai>
  • Loading branch information
FerdinandSpitzschnueffler committed Oct 14, 2022
1 parent 26a7c93 commit 404199e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2021 - 2022 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.
Expand Down Expand Up @@ -73,9 +73,8 @@ inline cxx::string<POSIX_CALL_ERROR_STRING_SIZE> errorLiteralToString(const char
template <typename T>
inline cxx::string<POSIX_CALL_ERROR_STRING_SIZE> PosixCallResult<T>::getHumanReadableErrnum() const noexcept
{
/// NOLINTJUSTIFICATION @todo iox-#1614 replace with upcoming uninitialized array
/// NOLINTNEXTLINE(hicpp-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays)
char buffer[POSIX_CALL_ERROR_STRING_SIZE];
containers::UnitializedArray<char, POSIX_CALL_ERROR_STRING_SIZE> buffer;
buffer[0] = '\0';
return internal::errorLiteralToString(strerror_r(errnum, &buffer[0], POSIX_CALL_ERROR_STRING_SIZE), &buffer[0]);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2021 - 2022 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.
Expand All @@ -16,6 +16,7 @@
#ifndef IOX_HOOFS_POSIX_WRAPPER_POSIX_CALL_HPP
#define IOX_HOOFS_POSIX_WRAPPER_POSIX_CALL_HPP

#include "iceoryx_hoofs/containers/uninitialized_array.hpp"
#include "iceoryx_hoofs/cxx/algorithm.hpp"
#include "iceoryx_hoofs/cxx/attributes.hpp"
#include "iceoryx_hoofs/cxx/expected.hpp"
Expand Down
13 changes: 4 additions & 9 deletions iceoryx_hoofs/source/posix_wrapper/posix_access_rights.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
// Copyright (c) 2021 - 2022 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.
Expand All @@ -16,7 +16,7 @@
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_hoofs/posix_wrapper/posix_access_rights.hpp"

#include "iceoryx_hoofs/containers/uninitialized_array.hpp"
#include "iceoryx_hoofs/posix_wrapper/posix_call.hpp"
#include "iceoryx_platform/grp.hpp"
#include "iceoryx_platform/platform_correction.hpp"
Expand Down Expand Up @@ -147,10 +147,7 @@ PosixUser::groupVector_t PosixUser::getGroups() const noexcept
}

gid_t userDefaultGroup = getpwnamCall->value->pw_gid;

/// NOLINTJUSTIFICATION @todo iox-#1614 use upcoming cxx::array
/// NOLINTNEXTLINE(hicpp-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays)
gid_t groups[MaxNumberOfGroups];
containers::UnitializedArray<gid_t, MaxNumberOfGroups> groups;
int32_t numGroups = MaxNumberOfGroups;

auto getgrouplistCall = posixCall(iox_getgrouplist)(userName->c_str(), userDefaultGroup, &groups[0], &numGroups)
Expand All @@ -171,9 +168,7 @@ PosixUser::groupVector_t PosixUser::getGroups() const noexcept
groupVector_t vec;
for (int32_t i = 0; i < numGroups; ++i)
{
/// NOLINTJUSTIFICATION @todo iox-#1614 will be fixed when upcoming cxx::array is used
/// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-constant-array-index)
vec.emplace_back(PosixGroup(groups[i]));
vec.emplace_back(PosixGroup(groups[static_cast<uint64_t>(i)]));
}

return vec;
Expand Down
5 changes: 2 additions & 3 deletions iceoryx_hoofs/source/posix_wrapper/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_hoofs/posix_wrapper/thread.hpp"
#include "iceoryx_hoofs/containers/uninitialized_array.hpp"
#include "iceoryx_hoofs/cxx/helplets.hpp"
#include "iceoryx_hoofs/log/logging.hpp"
#include "iceoryx_hoofs/posix_wrapper/posix_call.hpp"
Expand All @@ -35,9 +36,7 @@ void setThreadName(iox_pthread_t thread, const ThreadName_t& name) noexcept

ThreadName_t getThreadName(iox_pthread_t thread) noexcept
{
// NOLINTJUSTIFICATION required as name buffer for iox_pthread_getname_np
// NOLINTNEXTLINE(hicpp-avoid-c-arrays, cppcoreguidelines-avoid-c-arrays)
char tempName[MAX_THREAD_NAME_LENGTH + 1U];
containers::UnitializedArray<char, MAX_THREAD_NAME_LENGTH + 1> tempName;

posixCall(iox_pthread_getname_np)(thread, &tempName[0], MAX_THREAD_NAME_LENGTH + 1U)
.successReturnValue(0)
Expand Down
6 changes: 2 additions & 4 deletions iceoryx_hoofs/source/posix_wrapper/unix_domain_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,7 @@ UnixDomainSocket::timedReceive(const units::Duration& timeout) const noexcept
{
return cxx::error<IpcChannelError>(convertErrnoToIpcChannelError(setsockoptCall.get_error().errnum));
}
// NOLINTJUSTIFICATION needed for recvfrom
// NOLINTNEXTLINE(hicpp-avoid-c-arrays, cppcoreguidelines-avoid-c-arrays)
char message[MAX_MESSAGE_SIZE + 1];
containers::UnitializedArray<char, MAX_MESSAGE_SIZE + 1> message;

auto recvCall = posixCall(iox_recvfrom)(m_sockfd, &message[0], MAX_MESSAGE_SIZE, 0, nullptr, nullptr)
.failureReturnValue(ERROR_CODE)
Expand All @@ -293,7 +291,7 @@ UnixDomainSocket::timedReceive(const units::Duration& timeout) const noexcept
{
return cxx::error<IpcChannelError>(convertErrnoToIpcChannelError(recvCall.get_error().errnum));
}
return cxx::success<std::string>(message);
return cxx::success<std::string>(&message[0]);
}

cxx::expected<IpcChannelError> UnixDomainSocket::initalizeSocket() noexcept
Expand Down

0 comments on commit 404199e

Please sign in to comment.