diff --git a/score/memory/shared/fake/my_bounded_memory_resource.cpp b/score/memory/shared/fake/my_bounded_memory_resource.cpp index 594b64e2a..c827e2690 100644 --- a/score/memory/shared/fake/my_bounded_memory_resource.cpp +++ b/score/memory/shared/fake/my_bounded_memory_resource.cpp @@ -23,6 +23,7 @@ #include #include +#include namespace score::memory::shared::test { @@ -34,7 +35,7 @@ std::pair AllocateMemoryRange(const std::size_t memory_resource_si { auto* memory_allocation = static_cast(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(memory_resource_size))}; } } // namespace diff --git a/score/mw/com/doc/tutorial/chapter_1/provider.cpp b/score/mw/com/doc/tutorial/chapter_1/provider.cpp index c49114206..6b7af05fe 100644 --- a/score/mw/com/doc/tutorial/chapter_1/provider.cpp +++ b/score/mw/com/doc/tutorial/chapter_1/provider.cpp @@ -13,10 +13,13 @@ #include "score/mw/com/doc/tutorial/chapter_1/hello_world_service.h" #include "score/mw/com/types.h" +#include #include #include -#include +#include #include +#include +#include constexpr std::string_view kHelloWorld{"Hello World"}; namespace @@ -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(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())); diff --git a/score/mw/com/doc/tutorial/chapter_10/provider/provider.cpp b/score/mw/com/doc/tutorial/chapter_10/provider/provider.cpp index d0419acb0..bab8935f8 100644 --- a/score/mw/com/doc/tutorial/chapter_10/provider/provider.cpp +++ b/score/mw/com/doc/tutorial/chapter_10/provider/provider.cpp @@ -13,10 +13,13 @@ #include "score/mw/com/doc/tutorial/chapter_10/hello_world_service.h" #include "score/mw/com/types.h" +#include #include #include -#include +#include #include +#include +#include constexpr std::string_view kHelloWorld{"Hello World"}; namespace @@ -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(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())); diff --git a/score/mw/com/doc/tutorial/chapter_12/provider/skeleton_component.cpp b/score/mw/com/doc/tutorial/chapter_12/provider/skeleton_component.cpp index 82b05c98c..1a710fc1f 100644 --- a/score/mw/com/doc/tutorial/chapter_12/provider/skeleton_component.cpp +++ b/score/mw/com/doc/tutorial/chapter_12/provider/skeleton_component.cpp @@ -12,11 +12,14 @@ ********************************************************************************/ #include "score/mw/com/doc/tutorial/chapter_12/provider/skeleton_component.h" -#include +#include +#include #include #include +#include #include #include +#include namespace score::mw::com::tutorial { @@ -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(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())); diff --git a/score/mw/com/doc/tutorial/chapter_2/provider/provider.cpp b/score/mw/com/doc/tutorial/chapter_2/provider/provider.cpp index 1bbd83509..c13675d5e 100644 --- a/score/mw/com/doc/tutorial/chapter_2/provider/provider.cpp +++ b/score/mw/com/doc/tutorial/chapter_2/provider/provider.cpp @@ -13,10 +13,13 @@ #include "score/mw/com/doc/tutorial/chapter_2/hello_world_service.h" #include "score/mw/com/types.h" +#include #include #include -#include +#include #include +#include +#include constexpr std::string_view kHelloWorld{"Hello World"}; namespace @@ -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(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())); diff --git a/score/mw/com/doc/tutorial/chapter_3/provider/provider.cpp b/score/mw/com/doc/tutorial/chapter_3/provider/provider.cpp index 1f2e4fe1c..e0cffe3ff 100644 --- a/score/mw/com/doc/tutorial/chapter_3/provider/provider.cpp +++ b/score/mw/com/doc/tutorial/chapter_3/provider/provider.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -83,7 +84,7 @@ void SendSample(HelloWorldSkeleton& service_instance, 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())); diff --git a/score/mw/com/doc/tutorial/chapter_4/provider/provider.cpp b/score/mw/com/doc/tutorial/chapter_4/provider/provider.cpp index 8d5d569d4..277fa04c4 100644 --- a/score/mw/com/doc/tutorial/chapter_4/provider/provider.cpp +++ b/score/mw/com/doc/tutorial/chapter_4/provider/provider.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -61,7 +62,7 @@ void SendSample(HelloWorldSkeleton& service_instance, const std::size_t send_cou 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())); diff --git a/score/mw/com/doc/tutorial/chapter_5/provider/provider.cpp b/score/mw/com/doc/tutorial/chapter_5/provider/provider.cpp index b647997a3..4d8ea1257 100644 --- a/score/mw/com/doc/tutorial/chapter_5/provider/provider.cpp +++ b/score/mw/com/doc/tutorial/chapter_5/provider/provider.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -62,7 +63,7 @@ void SendSample(HelloWorldSkeleton& service_instance, const std::size_t send_cou 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())); diff --git a/score/mw/com/doc/tutorial/chapter_6/consumer/consumer.cpp b/score/mw/com/doc/tutorial/chapter_6/consumer/consumer.cpp index f96215ee0..fdd158d8c 100644 --- a/score/mw/com/doc/tutorial/chapter_6/consumer/consumer.cpp +++ b/score/mw/com/doc/tutorial/chapter_6/consumer/consumer.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -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] << " " << std::endl; + std::cerr << "Usage: " << *argv << " " << 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(parsed_max_sample_count); diff --git a/score/mw/com/doc/tutorial/chapter_6/provider/provider.cpp b/score/mw/com/doc/tutorial/chapter_6/provider/provider.cpp index fa74507c1..df4aba162 100644 --- a/score/mw/com/doc/tutorial/chapter_6/provider/provider.cpp +++ b/score/mw/com/doc/tutorial/chapter_6/provider/provider.cpp @@ -13,10 +13,13 @@ #include "score/mw/com/doc/tutorial/chapter_6/hello_world_service.h" #include "score/mw/com/types.h" +#include #include #include -#include +#include #include +#include +#include constexpr std::string_view kHelloWorld{"Hello World"}; namespace @@ -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(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())); diff --git a/score/mw/com/gateway/transport_layer/sample/message_framer.cpp b/score/mw/com/gateway/transport_layer/sample/message_framer.cpp index d8c3f3085..968963b81 100644 --- a/score/mw/com/gateway/transport_layer/sample/message_framer.cpp +++ b/score/mw/com/gateway/transport_layer/sample/message_framer.cpp @@ -17,6 +17,9 @@ #include +#include +#include + namespace score::mw::com::gateway { @@ -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(result.value()); - ptr += sent; + ptr = std::next(ptr, static_cast(sent)); length -= sent; } return 0; @@ -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(result.value()); - ptr += received; + ptr = std::next(ptr, static_cast(received)); length -= received; } return static_cast(original_length); diff --git a/score/mw/com/gateway/transport_layer/sample/test/app1_main.cpp b/score/mw/com/gateway/transport_layer/sample/test/app1_main.cpp index 4af469f26..6983efc00 100644 --- a/score/mw/com/gateway/transport_layer/sample/test/app1_main.cpp +++ b/score/mw/com/gateway/transport_layer/sample/test/app1_main.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -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); } if (mode == "reconnect") diff --git a/score/mw/com/gateway/transport_layer/sample/test/app2_main.cpp b/score/mw/com/gateway/transport_layer/sample/test/app2_main.cpp index ff272af35..c6353c82e 100644 --- a/score/mw/com/gateway/transport_layer/sample/test/app2_main.cpp +++ b/score/mw/com/gateway/transport_layer/sample/test/app2_main.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -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") diff --git a/score/mw/com/impl/bindings/lola/application_id_pid_mapping.cpp b/score/mw/com/impl/bindings/lola/application_id_pid_mapping.cpp index 4da7bf84f..cf3937994 100644 --- a/score/mw/com/impl/bindings/lola/application_id_pid_mapping.cpp +++ b/score/mw/com/impl/bindings/lola/application_id_pid_mapping.cpp @@ -14,6 +14,8 @@ #include "score/mw/log/logging.h" +#include + namespace score::mw::com::impl::lola { @@ -46,7 +48,7 @@ std::optional 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(); @@ -114,7 +116,7 @@ std::optional RegisterPid(score::containers::DynamicArrayGetStatusAndApplicationIdAtomic(); const auto entry_status = status_applicationid.first; diff --git a/score/mw/com/impl/bindings/lola/messaging/message_passing_service_instance.cpp b/score/mw/com/impl/bindings/lola/messaging/message_passing_service_instance.cpp index b5d2a7410..72b7b52cf 100644 --- a/score/mw/com/impl/bindings/lola/messaging/message_passing_service_instance.cpp +++ b/score/mw/com/impl/bindings/lola/messaging/message_passing_service_instance.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -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(&t); - const auto* const source_end = source_begin + sizeof(T); + const auto* const source_end = std::next(source_begin, static_cast(sizeof(T))); std::copy(source_begin, source_end, std::next(out.begin())); return out; } diff --git a/score/mw/com/impl/bindings/lola/transaction_log_set.cpp b/score/mw/com/impl/bindings/lola/transaction_log_set.cpp index b7826bb68..8b73ac2a0 100644 --- a/score/mw/com/impl/bindings/lola/transaction_log_set.cpp +++ b/score/mw/com/impl/bindings/lola/transaction_log_set.cpp @@ -19,6 +19,7 @@ #include +#include #include #include @@ -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] @@ -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; diff --git a/score/mw/com/runtime_configuration.cpp b/score/mw/com/runtime_configuration.cpp index 8bf1eb7b3..52eb570ab 100644 --- a/score/mw/com/runtime_configuration.cpp +++ b/score/mw/com/runtime_configuration.cpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include #include @@ -52,7 +52,7 @@ RuntimeConfiguration::RuntimeConfiguration(const std::int32_t argc, const char* std::vector command_line_arguments{}; for (std::int32_t arg_idx = 0U; arg_idx < argc; arg_idx++) { - auto argument = std::string_view{argv[arg_idx]}; + auto argument = std::string_view{*std::next(argv, arg_idx)}; command_line_arguments.push_back(safecpp::zstring_view{argument.data(), argument.size()}); } diff --git a/score/mw/com/test/generic_skeleton/generic_generic_interaction_app.cpp b/score/mw/com/test/generic_skeleton/generic_generic_interaction_app.cpp index 0078a7cda..70e366020 100644 --- a/score/mw/com/test/generic_skeleton/generic_generic_interaction_app.cpp +++ b/score/mw/com/test/generic_skeleton/generic_generic_interaction_app.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include @@ -223,8 +223,8 @@ int main(int argc, const char* argv[]) { std::string mode; for (int i = 1; i < argc; ++i) - if (std::string(argv[i]) == "--mode" && i + 1 < argc) - mode = argv[++i]; + if (std::string(*std::next(argv, i)) == "--mode" && i + 1 < argc) + mode = *std::next(argv, ++i); score::mw::com::runtime::InitializeRuntime(score::mw::com::runtime::RuntimeConfiguration(argc, argv)); score::cpp::stop_source stop_source{}; diff --git a/score/mw/com/test/generic_skeleton/generic_typed_interaction_app.cpp b/score/mw/com/test/generic_skeleton/generic_typed_interaction_app.cpp index 4a7f77040..86730ce74 100644 --- a/score/mw/com/test/generic_skeleton/generic_typed_interaction_app.cpp +++ b/score/mw/com/test/generic_skeleton/generic_typed_interaction_app.cpp @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include @@ -219,10 +219,10 @@ int main(int argc, const char* argv[]) std::string mode; for (int i = 1; i < argc; ++i) { - std::string arg = argv[i]; + std::string arg = *std::next(argv, i); if (arg == "--mode" && i + 1 < argc) { - mode = argv[++i]; + mode = *std::next(argv, ++i); } }