From 76af910f0e6823caaae1e90b36b73e276f7dcfc8 Mon Sep 17 00:00:00 2001 From: Jan Schlosser Date: Wed, 26 Aug 2026 11:07:37 +0200 Subject: [PATCH 1/3] fix(clang-tidy): resolve cppcoreguidelines-pro-bounds-pointer-arithmetic findings Replaces raw pointer arithmetic (`ptr + n`, `ptr += n`, `ptr[n]`, `ptr++`) with `std::next()`-based equivalents throughout the codebase, since ``'s `std::next`/`std::advance` perform the arithmetic inside the standard library (excluded by HeaderFilterRegex) instead of at the call site, which is the idiomatic fix recommended by the C++ Core Guidelines' Bounds Profile for this exact pattern. All changes are pure syntax transformations with identical runtime semantics - no behavioral change. Patterns fixed: - `buf + n` / `buf[n]` -> `std::next(buf, n)` / `*std::next(buf, n)` for writing at an offset into a raw buffer (tutorial chapters 1/2/3/4/5/6/10/12, gateway sample apps). - `ptr += n` -> `ptr = std::next(ptr, n)` for advancing a buffer cursor in a send/receive loop (message_framer.cpp). - `argv[i]` -> `*std::next(argv, i)` for command-line argument access (consumer.cpp, app1_main.cpp, app2_main.cpp, runtime_configuration.cpp, generic_generic_interaction_app.cpp, generic_typed_interaction_app.cpp). - `it++` -> `it = std::next(it)` for raw-pointer-typed container iteration in for-loop increment clauses (application_id_pid_mapping.cpp, transaction_log_set.cpp). - `ptr + sizeof(T)` -> `std::next(ptr, sizeof(T))` for computing a byte range end pointer (message_passing_service_instance.cpp). - `ptr + n` -> `std::next(ptr, n)` for computing an end-of-buffer pointer (my_bounded_memory_resource.cpp). Where the distance argument was an unsigned `std::size_t`, added an explicit `static_cast(...)` to avoid introducing a `-Wsign-conversion` error, since `std::next`'s distance parameter is the iterator's (signed) `difference_type`. Added `#include ` (and `` where `std::ptrdiff_t` was newly needed) to each affected translation unit. Verified: - Full build (`bazel build //score/mw/com/... //score/memory/... //score/message_passing/...`) passes. - Scoped clang-tidy build isolated to cppcoreguidelines-pro-bounds-pointer-arithmetic shows 0 findings (down from 26 findings across 12 files). - 119 tests pass (1 pre-existing skip, unrelated) across score/mw/com/gateway/..., score/mw/com/impl/bindings/lola/..., score/memory/shared/..., score/mw/com/test/generic_skeleton/..., and score/mw/com:runtime_configuration_test. - Tutorial doc targets under score/mw/com/doc/tutorial/... build successfully. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- score/memory/shared/fake/my_bounded_memory_resource.cpp | 3 ++- score/mw/com/doc/tutorial/chapter_1/provider.cpp | 3 ++- .../mw/com/doc/tutorial/chapter_10/provider/provider.cpp | 3 ++- .../tutorial/chapter_12/provider/skeleton_component.cpp | 3 ++- score/mw/com/doc/tutorial/chapter_2/provider/provider.cpp | 3 ++- score/mw/com/doc/tutorial/chapter_3/provider/provider.cpp | 3 ++- score/mw/com/doc/tutorial/chapter_4/provider/provider.cpp | 3 ++- score/mw/com/doc/tutorial/chapter_5/provider/provider.cpp | 3 ++- score/mw/com/doc/tutorial/chapter_6/consumer/consumer.cpp | 8 +++++--- score/mw/com/doc/tutorial/chapter_6/provider/provider.cpp | 3 ++- .../com/gateway/transport_layer/sample/message_framer.cpp | 7 +++++-- .../com/gateway/transport_layer/sample/test/app1_main.cpp | 3 ++- .../com/gateway/transport_layer/sample/test/app2_main.cpp | 3 ++- .../com/impl/bindings/lola/application_id_pid_mapping.cpp | 6 ++++-- .../lola/messaging/message_passing_service_instance.cpp | 3 ++- score/mw/com/impl/bindings/lola/transaction_log_set.cpp | 5 +++-- score/mw/com/runtime_configuration.cpp | 4 ++-- .../generic_skeleton/generic_generic_interaction_app.cpp | 6 +++--- .../generic_skeleton/generic_typed_interaction_app.cpp | 6 +++--- 19 files changed, 49 insertions(+), 29 deletions(-) diff --git a/score/memory/shared/fake/my_bounded_memory_resource.cpp b/score/memory/shared/fake/my_bounded_memory_resource.cpp index 594b64e2a1..c827e26908 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 c49114206b..b8bc736034 100644 --- a/score/mw/com/doc/tutorial/chapter_1/provider.cpp +++ b/score/mw/com/doc/tutorial/chapter_1/provider.cpp @@ -17,6 +17,7 @@ #include #include #include +#include constexpr std::string_view kHelloWorld{"Hello World"}; namespace @@ -66,7 +67,7 @@ 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); + const auto chars_written = std::snprintf(std::next(buf, kHelloWorld.size()), remaining, "%zu", send_counter); if (chars_written < 0) { std::cerr << "Failed to write 'send_counter' to sample_allocatee_ptr!" << std::endl; 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 d0419acb0e..0a57b339db 100644 --- a/score/mw/com/doc/tutorial/chapter_10/provider/provider.cpp +++ b/score/mw/com/doc/tutorial/chapter_10/provider/provider.cpp @@ -17,6 +17,7 @@ #include #include #include +#include constexpr std::string_view kHelloWorld{"Hello World"}; namespace @@ -66,7 +67,7 @@ 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); + const auto chars_written = std::snprintf(std::next(buf, kHelloWorld.size()), remaining, "%zu", send_counter); if (chars_written < 0) { std::cerr << "Failed to write 'send_counter' to sample_allocatee_ptr!" << std::endl; 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 82b05c98c2..82b26299fb 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 @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -49,7 +50,7 @@ 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); + const auto chars_written = std::snprintf(std::next(buf, kHelloWorld.size()), remaining, "%zu", send_counter); if (chars_written < 0) { std::cerr << "Failed to write 'send_counter' to sample_allocatee_ptr!" << std::endl; 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 1bbd835098..2e8573279f 100644 --- a/score/mw/com/doc/tutorial/chapter_2/provider/provider.cpp +++ b/score/mw/com/doc/tutorial/chapter_2/provider/provider.cpp @@ -17,6 +17,7 @@ #include #include #include +#include constexpr std::string_view kHelloWorld{"Hello World"}; namespace @@ -66,7 +67,7 @@ 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); + const auto chars_written = std::snprintf(std::next(buf, kHelloWorld.size()), remaining, "%zu", send_counter); if (chars_written < 0) { std::cerr << "Failed to write 'send_counter' to sample_allocatee_ptr!" << std::endl; 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 1f2e4fe1c0..e0cffe3ff7 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 8d5d569d48..277fa04c4c 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 b647997a30..4d8ea1257f 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 f96215ee0b..872292a4c5 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 fa74507c15..3be1230c0f 100644 --- a/score/mw/com/doc/tutorial/chapter_6/provider/provider.cpp +++ b/score/mw/com/doc/tutorial/chapter_6/provider/provider.cpp @@ -17,6 +17,7 @@ #include #include #include +#include constexpr std::string_view kHelloWorld{"Hello World"}; namespace @@ -66,7 +67,7 @@ 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); + const auto chars_written = std::snprintf(std::next(buf, kHelloWorld.size()), remaining, "%zu", send_counter); if (chars_written < 0) { std::cerr << "Failed to write 'send_counter' to sample_allocatee_ptr!" << std::endl; 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 d8c3f30854..968963b815 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 4af469f266..6983efc00a 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 ff272af35b..c6353c82e5 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 4da7bf84f9..cf39379945 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 b5d2a7410b..72b7b52cf2 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 b7826bb682..8b73ac2a00 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 8bf1eb7b36..52eb570ab3 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 0078a7cdae..70e366020b 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 4a7f770400..86730ce743 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); } } From 36d954832ab43f02fa3b6f09a78c357dc086b164 Mon Sep 17 00:00:00 2001 From: Jan Schlosser Date: Wed, 26 Aug 2026 11:40:01 +0200 Subject: [PATCH 2/3] fix: apply clang-format to consumer.cpp Fixes a formatting violation introduced by the std::next() conversion in the previous commit (line wrap of the std::cerr chain was off by one indentation level). No functional change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- score/mw/com/doc/tutorial/chapter_6/consumer/consumer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 872292a4c5..fdd158d8c1 100644 --- a/score/mw/com/doc/tutorial/chapter_6/consumer/consumer.cpp +++ b/score/mw/com/doc/tutorial/chapter_6/consumer/consumer.cpp @@ -60,7 +60,7 @@ int main(int argc, const char** argv) if (parsed_max_sample_count <= 0) { std::cerr << "Invalid max_sample_count '" << *std::next(argv, 1) << "'. It must be a positive integer." - << std::endl; + << std::endl; return EXIT_FAILURE; } const auto max_sample_count = static_cast(parsed_max_sample_count); From a70d9a8081276e1173f67f31f07e3c45ba9875ea Mon Sep 17 00:00:00 2001 From: Jan Schlosser Date: Wed, 26 Aug 2026 12:41:46 +0200 Subject: [PATCH 3/3] fix(clang-tidy): resolve cppcoreguidelines-pro-type-vararg findings introduced by std::next() conversion The earlier std::next() conversion (for cppcoreguidelines-pro-bounds-pointer-arithmetic) left the `std::snprintf(std::next(buf, ...), remaining, "%zu", send_counter)` call sites untouched. `std::snprintf` is itself a C-style vararg function, so it now triggers cppcoreguidelines-pro-type-vararg. Since these lines are part of this PR's diff, fix them here too rather than leaving a new finding behind. Replaces the printf-style `std::snprintf` call with `std::to_chars` (C++17, ), which writes the integer directly without going through a variadic/format-string interface. `std::to_chars` does not null-terminate its output, so a trailing '\0' is written explicitly at the returned pointer (one byte of the original `remaining` budget is reserved for it, matching the space snprintf's `remaining` argument always implied), preserving the "print info to the reader" via `buf` as a null-terminated C-string) as before. Affected: the 5 tutorial provider samples that reference `kHelloWorld` and print a numeric send_counter into the sample buffer (chapters 1, 2, 6, 10, 12). Added `#include ` and `#include ` (for `std::errc`); removed the now-unused `#include `. Verified: - Scoped clang-tidy build isolated to cppcoreguidelines-pro-type-vararg over //score/mw/com/doc/tutorial/... shows 0 findings in these 5 files (down from 5; 2 pre-existing findings in unrelated, untouched files remain, out of scope for this PR). - `bazel build //score/mw/com/doc/tutorial/...` passes. - `bazel test //:format_test_C++_with_clang-format` passes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- score/mw/com/doc/tutorial/chapter_1/provider.cpp | 11 ++++++++--- .../com/doc/tutorial/chapter_10/provider/provider.cpp | 11 ++++++++--- .../chapter_12/provider/skeleton_component.cpp | 11 ++++++++--- .../com/doc/tutorial/chapter_2/provider/provider.cpp | 11 ++++++++--- .../com/doc/tutorial/chapter_6/provider/provider.cpp | 11 ++++++++--- 5 files changed, 40 insertions(+), 15 deletions(-) diff --git a/score/mw/com/doc/tutorial/chapter_1/provider.cpp b/score/mw/com/doc/tutorial/chapter_1/provider.cpp index b8bc736034..6b7af05fe9 100644 --- a/score/mw/com/doc/tutorial/chapter_1/provider.cpp +++ b/score/mw/com/doc/tutorial/chapter_1/provider.cpp @@ -13,11 +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 @@ -67,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(std::next(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 0a57b339db..bab8935f85 100644 --- a/score/mw/com/doc/tutorial/chapter_10/provider/provider.cpp +++ b/score/mw/com/doc/tutorial/chapter_10/provider/provider.cpp @@ -13,11 +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 @@ -67,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(std::next(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 82b26299fb..1a710fc1f9 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,12 +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 { @@ -50,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(std::next(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 2e8573279f..c13675d5ed 100644 --- a/score/mw/com/doc/tutorial/chapter_2/provider/provider.cpp +++ b/score/mw/com/doc/tutorial/chapter_2/provider/provider.cpp @@ -13,11 +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 @@ -67,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(std::next(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_6/provider/provider.cpp b/score/mw/com/doc/tutorial/chapter_6/provider/provider.cpp index 3be1230c0f..df4aba1624 100644 --- a/score/mw/com/doc/tutorial/chapter_6/provider/provider.cpp +++ b/score/mw/com/doc/tutorial/chapter_6/provider/provider.cpp @@ -13,11 +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 @@ -67,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(std::next(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()));