Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion score/memory/shared/fake/my_bounded_memory_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <cstddef>
#include <cstdint>
#include <iterator>

namespace score::memory::shared::test
{
Expand All @@ -34,7 +35,7 @@ std::pair<void*, void*> AllocateMemoryRange(const std::size_t memory_resource_si
{
auto* memory_allocation = static_cast<std::uint8_t*>(std::malloc(memory_resource_size));
SCORE_LANGUAGE_FUTURECPP_ASSERT_MESSAGE(memory_allocation != nullptr, "Malloc must return allocated memory!");
return {memory_allocation, memory_allocation + memory_resource_size};
return {memory_allocation, std::next(memory_allocation, static_cast<std::ptrdiff_t>(memory_resource_size))};
}

} // namespace
Expand Down
12 changes: 9 additions & 3 deletions score/mw/com/doc/tutorial/chapter_1/provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
#include "score/mw/com/doc/tutorial/chapter_1/hello_world_service.h"
#include "score/mw/com/types.h"

#include <charconv>
#include <atomic>
#include <csignal>
#include <cstdio>
#include <cstddef>
#include <cstring>
#include <iterator>
#include <system_error>

constexpr std::string_view kHelloWorld{"Hello World"};
namespace
Expand Down Expand Up @@ -66,12 +69,15 @@ int main()
std::memcpy(sample_allocatee_ptr.value().Get()->data(), kHelloWorld.data(), kHelloWorld.size());
auto* buf = sample_allocatee_ptr.value().Get()->data();
const auto remaining = sample_allocatee_ptr.value().Get()->size() - kHelloWorld.size();
const auto chars_written = std::snprintf(buf + kHelloWorld.size(), remaining, "%zu", send_counter);
if (chars_written < 0)
auto* const number_start = std::next(buf, kHelloWorld.size());
const auto to_chars_result = std::to_chars(
number_start, std::next(number_start, static_cast<std::ptrdiff_t>(remaining) - 1), send_counter);
if (to_chars_result.ec != std::errc{})
{
std::cerr << "Failed to write 'send_counter' to sample_allocatee_ptr!" << std::endl;
exit(1);
}
*to_chars_result.ptr = '\0';

// Send the new event sample (make it visible to potential consumers)
auto send_result = hello_world_service_instance.message.Send(std::move(sample_allocatee_ptr.value()));
Expand Down
12 changes: 9 additions & 3 deletions score/mw/com/doc/tutorial/chapter_10/provider/provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
#include "score/mw/com/doc/tutorial/chapter_10/hello_world_service.h"
#include "score/mw/com/types.h"

#include <charconv>
#include <atomic>
#include <csignal>
#include <cstdio>
#include <cstddef>
#include <cstring>
#include <iterator>
#include <system_error>

constexpr std::string_view kHelloWorld{"Hello World"};
namespace
Expand Down Expand Up @@ -66,12 +69,15 @@ int main()
std::memcpy(sample_allocatee_ptr.value().Get()->data(), kHelloWorld.data(), kHelloWorld.size());
auto* buf = sample_allocatee_ptr.value().Get()->data();
const auto remaining = sample_allocatee_ptr.value().Get()->size() - kHelloWorld.size();
const auto chars_written = std::snprintf(buf + kHelloWorld.size(), remaining, "%zu", send_counter);
if (chars_written < 0)
auto* const number_start = std::next(buf, kHelloWorld.size());
const auto to_chars_result = std::to_chars(
number_start, std::next(number_start, static_cast<std::ptrdiff_t>(remaining) - 1), send_counter);
if (to_chars_result.ec != std::errc{})
{
std::cerr << "Failed to write 'send_counter' to sample_allocatee_ptr!" << std::endl;
exit(1);
}
*to_chars_result.ptr = '\0';

// Send the new event sample (make it visible to potential consumers)
auto send_result = hello_world_service_instance.message.Send(std::move(sample_allocatee_ptr.value()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
********************************************************************************/
#include "score/mw/com/doc/tutorial/chapter_12/provider/skeleton_component.h"

#include <cstdio>
#include <charconv>
#include <cstddef>
#include <cstring>
#include <iostream>
#include <iterator>
#include <string>
#include <string_view>
#include <system_error>

namespace score::mw::com::tutorial
{
Expand Down Expand Up @@ -49,12 +52,15 @@ SkeletonComponent::SendSampleResult SkeletonComponent::SendSample(std::size_t se
std::memcpy(sample_allocatee_ptr.value().Get()->data(), kHelloWorld.data(), kHelloWorld.size());
auto* buf = sample_allocatee_ptr.value().Get()->data();
const auto remaining = sample_allocatee_ptr.value().Get()->size() - kHelloWorld.size();
const auto chars_written = std::snprintf(buf + kHelloWorld.size(), remaining, "%zu", send_counter);
if (chars_written < 0)
auto* const number_start = std::next(buf, kHelloWorld.size());
const auto to_chars_result =
std::to_chars(number_start, std::next(number_start, static_cast<std::ptrdiff_t>(remaining) - 1), send_counter);
if (to_chars_result.ec != std::errc{})
{
std::cerr << "Failed to write 'send_counter' to sample_allocatee_ptr!" << std::endl;
return SendSampleResult::kFatalError;
}
*to_chars_result.ptr = '\0';

const std::string payload_for_log{buf};
auto send_result = hello_world_skeleton_->message.Send(std::move(sample_allocatee_ptr.value()));
Expand Down
12 changes: 9 additions & 3 deletions score/mw/com/doc/tutorial/chapter_2/provider/provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
#include "score/mw/com/doc/tutorial/chapter_2/hello_world_service.h"
#include "score/mw/com/types.h"

#include <charconv>
#include <atomic>
#include <csignal>
#include <cstdio>
#include <cstddef>
#include <cstring>
#include <iterator>
#include <system_error>

constexpr std::string_view kHelloWorld{"Hello World"};
namespace
Expand Down Expand Up @@ -66,12 +69,15 @@ int main()
std::memcpy(sample_allocatee_ptr.value().Get()->data(), kHelloWorld.data(), kHelloWorld.size());
auto* buf = sample_allocatee_ptr.value().Get()->data();
const auto remaining = sample_allocatee_ptr.value().Get()->size() - kHelloWorld.size();
const auto chars_written = std::snprintf(buf + kHelloWorld.size(), remaining, "%zu", send_counter);
if (chars_written < 0)
auto* const number_start = std::next(buf, kHelloWorld.size());
const auto to_chars_result = std::to_chars(
number_start, std::next(number_start, static_cast<std::ptrdiff_t>(remaining) - 1), send_counter);
if (to_chars_result.ec != std::errc{})
{
std::cerr << "Failed to write 'send_counter' to sample_allocatee_ptr!" << std::endl;
exit(1);
}
*to_chars_result.ptr = '\0';

// Send the new event sample (make it visible to potential consumers)
auto send_result = hello_world_service_instance.message.Send(std::move(sample_allocatee_ptr.value()));
Expand Down
3 changes: 2 additions & 1 deletion score/mw/com/doc/tutorial/chapter_3/provider/provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <csignal>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <string>
#include <string_view>
#include <vector>
Expand Down Expand Up @@ -83,7 +84,7 @@
const auto capacity = sample_allocatee_ptr.value().Get()->size();
const auto chars_to_copy = std::min(message.size(), capacity - 1U);
std::memcpy(buf, message.data(), chars_to_copy);
buf[chars_to_copy] = '\0';
*std::next(buf, chars_to_copy) = '\0';

// Send the new event sample (make it visible to potential consumers)
auto send_result = service_instance.message.Send(std::move(sample_allocatee_ptr.value()));
Expand Down
3 changes: 2 additions & 1 deletion score/mw/com/doc/tutorial/chapter_4/provider/provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <chrono>
#include <csignal>
#include <cstring>
#include <iterator>
#include <string>
#include <string_view>
#include <thread>
Expand Down Expand Up @@ -61,7 +62,7 @@
const auto capacity = sample_allocatee_ptr.value().Get()->size();
const auto chars_to_copy = std::min(message.size(), capacity - 1U);
std::memcpy(buf, message.data(), chars_to_copy);
buf[chars_to_copy] = '\0';
*std::next(buf, chars_to_copy) = '\0';

// Send the new event sample (make it visible to potential consumers)
auto send_result = service_instance.message.Send(std::move(sample_allocatee_ptr.value()));
Expand Down
3 changes: 2 additions & 1 deletion score/mw/com/doc/tutorial/chapter_5/provider/provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <chrono>
#include <csignal>
#include <cstring>
#include <iterator>
#include <random>
#include <string>
#include <string_view>
Expand Down Expand Up @@ -62,7 +63,7 @@
const auto capacity = sample_allocatee_ptr.value().Get()->size();
const auto chars_to_copy = std::min(message.size(), capacity - 1U);
std::memcpy(buf, message.data(), chars_to_copy);
buf[chars_to_copy] = '\0';
*std::next(buf, chars_to_copy) = '\0';

// Send the new event sample (make it visible to potential consumers)
auto send_result = service_instance.message.Send(std::move(sample_allocatee_ptr.value()));
Expand Down
8 changes: 5 additions & 3 deletions score/mw/com/doc/tutorial/chapter_6/consumer/consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <optional>
#include <string>
#include <thread>
Expand Down Expand Up @@ -52,13 +53,14 @@ int main(int argc, const char** argv)
// expresses how many samples (SamplePtrs) the consumer wants to be able to hold in parallel.
if (argc != 2)
{
std::cerr << "Usage: " << argv[0] << " <max_sample_count>" << std::endl;
std::cerr << "Usage: " << *argv << " <max_sample_count>" << std::endl;
return EXIT_FAILURE;
}
const auto parsed_max_sample_count = std::atoi(argv[1]);
const auto parsed_max_sample_count = std::atoi(*std::next(argv, 1));
if (parsed_max_sample_count <= 0)
{
std::cerr << "Invalid max_sample_count '" << argv[1] << "'. It must be a positive integer." << std::endl;
std::cerr << "Invalid max_sample_count '" << *std::next(argv, 1) << "'. It must be a positive integer."
<< std::endl;
return EXIT_FAILURE;
}
const auto max_sample_count = static_cast<std::size_t>(parsed_max_sample_count);
Expand Down
12 changes: 9 additions & 3 deletions score/mw/com/doc/tutorial/chapter_6/provider/provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
#include "score/mw/com/doc/tutorial/chapter_6/hello_world_service.h"
#include "score/mw/com/types.h"

#include <charconv>
#include <atomic>
#include <csignal>
#include <cstdio>
#include <cstddef>
#include <cstring>
#include <iterator>
#include <system_error>

constexpr std::string_view kHelloWorld{"Hello World"};
namespace
Expand Down Expand Up @@ -66,12 +69,15 @@ int main()
std::memcpy(sample_allocatee_ptr.value().Get()->data(), kHelloWorld.data(), kHelloWorld.size());
auto* buf = sample_allocatee_ptr.value().Get()->data();
const auto remaining = sample_allocatee_ptr.value().Get()->size() - kHelloWorld.size();
const auto chars_written = std::snprintf(buf + kHelloWorld.size(), remaining, "%zu", send_counter);
if (chars_written < 0)
auto* const number_start = std::next(buf, kHelloWorld.size());
const auto to_chars_result = std::to_chars(
number_start, std::next(number_start, static_cast<std::ptrdiff_t>(remaining) - 1), send_counter);
if (to_chars_result.ec != std::errc{})
{
std::cerr << "Failed to write 'send_counter' to sample_allocatee_ptr!" << std::endl;
exit(1);
}
*to_chars_result.ptr = '\0';

// Send the new event sample (make it visible to potential consumers)
auto send_result = hello_world_service_instance.message.Send(std::move(sample_allocatee_ptr.value()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

#include <score/span.hpp>

#include <cstddef>
#include <iterator>

namespace score::mw::com::gateway
{

Expand All @@ -37,7 +40,7 @@ int SendAll(std::int32_t socket_fd, const void* data, std::size_t length)
return -1;
}
const auto sent = static_cast<std::size_t>(result.value());
ptr += sent;
ptr = std::next(ptr, static_cast<std::ptrdiff_t>(sent));
length -= sent;
}
return 0;
Expand Down Expand Up @@ -66,7 +69,7 @@ ssize_t ReceiveAll(std::int32_t socket_fd, void* buffer, std::size_t length)
return 0;
}
const auto received = static_cast<std::size_t>(result.value());
ptr += received;
ptr = std::next(ptr, static_cast<std::ptrdiff_t>(received));
length -= received;
}
return static_cast<ssize_t>(original_length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include <atomic>
#include <iostream>
#include <iterator>
#include <string>
#include <thread>

Expand Down Expand Up @@ -161,7 +162,7 @@ int main(int argc, char* argv[])
std::string mode = "regular_case";
if (argc > 1)
{
mode = argv[1];
mode = *std::next(argv, 1);
Comment on lines -164 to +165

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whether this makes it better or worse. While it now is modern C++ syntax, the readability of this statement is degraded significantly...

}

if (mode == "reconnect")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include <atomic>
#include <iostream>
#include <iterator>
#include <string>
#include <thread>

Expand Down Expand Up @@ -191,7 +192,7 @@ int main(int argc, char* argv[])
std::string mode = "regular_case";
if (argc > 1)
{
mode = argv[1];
mode = *std::next(argv, 1);
}

if (mode == "reconnect")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "score/mw/log/logging.h"

#include <iterator>

namespace score::mw::com::impl::lola
{

Expand Down Expand Up @@ -46,7 +48,7 @@ std::optional<pid_t> TryUpdatePidForExistingId(
// Rationale: Tolerated due to containers providing pointer-like iterators.
// The Coverity tool considers these iterators as raw pointers.
// coverity[autosar_cpp14_m5_0_15_violation]
for (auto* it = entries_begin; it != entries_end; it++)
for (auto* it = entries_begin; it != entries_end; it = std::next(it))
{
// extract out into a separate function
const auto status_applicationid = it->GetStatusAndApplicationIdAtomic();
Expand Down Expand Up @@ -114,7 +116,7 @@ std::optional<pid_t> RegisterPid(score::containers::DynamicArray<ApplicationIdPi
// Rationale: Tolerated due to containers providing pointer-like iterators.
// The Coverity tool considers these iterators as raw pointers.
// coverity[autosar_cpp14_m5_0_15_violation]
for (auto* it = entries_begin; it != entries_end; it++)
for (auto* it = entries_begin; it != entries_end; it = std::next(it))
{
const auto status_applicationid = it->GetStatusAndApplicationIdAtomic();
const auto entry_status = status_applicationid.first;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <algorithm>
#include <array>
#include <cerrno>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <exception>
Expand Down Expand Up @@ -152,7 +153,7 @@ auto SerializeToMessage(const std::uint8_t message_id, const T& t) noexcept -> s
// source range directly from the same pointer (source_begin / source_end) that is copied keeps the range
// trivially self-consistent for every instantiation of T.
const auto* const source_begin = reinterpret_cast<const std::uint8_t*>(&t);
const auto* const source_end = source_begin + sizeof(T);
const auto* const source_end = std::next(source_begin, static_cast<std::ptrdiff_t>(sizeof(T)));
std::copy(source_begin, source_end, std::next(out.begin()));
return out;
}
Expand Down
5 changes: 3 additions & 2 deletions score/mw/com/impl/bindings/lola/transaction_log_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <score/assert.hpp>

#include <iterator>
#include <limits>
#include <mutex>

Expand Down Expand Up @@ -205,7 +206,7 @@ TransactionLogSet::FindTransactionLogNodesToBeRolledBack(const TransactionLogId&
//
// coverity[autosar_cpp14_m5_0_15_violation]
// coverity[autosar_cpp14_a5_3_2_violation : FALSE]
for (auto* it = proxy_transaction_logs_.begin(); it != proxy_transaction_logs_.end(); it++)
for (auto* it = proxy_transaction_logs_.begin(); it != proxy_transaction_logs_.end(); it = std::next(it))
{
// LCOV_EXCL_BR_STOP
// coverity[autosar_cpp14_a5_3_2_violation : FALSE]
Expand Down Expand Up @@ -247,7 +248,7 @@ TransactionLogSet::AcquireNextAvailableSlot(TransactionLogId transaction_log_id)
//
// coverity[autosar_cpp14_m5_0_15_violation]
// coverity[autosar_cpp14_a5_3_2_violation : FALSE]
for (auto* it = proxy_transaction_logs_.begin(); it != proxy_transaction_logs_.end(); it++)
for (auto* it = proxy_transaction_logs_.begin(); it != proxy_transaction_logs_.end(); it = std::next(it))
{
// LCOV_EXCL_BR_STOP
auto& transaction_log_node = *it;
Expand Down
Loading
Loading