diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index fe4bb1aba1..eba11307ce 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -46,3 +46,20 @@ jobs: name: clang-tidy-report path: build/clang-tidy-report.txt retention-days: 14 + + - name: Convert clang-tidy report to Allure JUnit XML + if: always() + run: | + THRESHOLD=$(head -1 clang-tidy-baseline.txt 2>/dev/null | tr -d '[:space:]') + python3 scripts/clang_tidy_to_allure.py \ + build/clang-tidy-report.txt \ + allure-results \ + ${THRESHOLD:+--threshold "$THRESHOLD"} + + - name: Upload Allure results + uses: actions/upload-artifact@v4 + if: always() + with: + name: allure-results-clang-tidy + path: allure-results/ + retention-days: 14 diff --git a/clang-tidy-baseline.txt b/clang-tidy-baseline.txt index 7e8e81804f..e45b99e958 100644 --- a/clang-tidy-baseline.txt +++ b/clang-tidy-baseline.txt @@ -1 +1 @@ -1783 +384 diff --git a/include/core/session_manager.h b/include/core/session_manager.h index 261cde173f..ff0be35e04 100644 --- a/include/core/session_manager.h +++ b/include/core/session_manager.h @@ -130,14 +130,14 @@ class SessionManager { */ size_t get_active_session_count() const; + // Prevent copying + SessionManager(const SessionManager&) = delete; + SessionManager& operator=(const SessionManager&) = delete; + private: std::unordered_map> sessions_; mutable platform::Mutex sessions_mutex_; uint16_t next_session_id_{1}; - - // Prevent copying - SessionManager(const SessionManager&) = delete; - SessionManager& operator=(const SessionManager&) = delete; }; } // namespace someip diff --git a/include/e2e/e2e_profile_registry.h b/include/e2e/e2e_profile_registry.h index 71cecf4ac7..8fbf4287d6 100644 --- a/include/e2e/e2e_profile_registry.h +++ b/include/e2e/e2e_profile_registry.h @@ -77,11 +77,12 @@ class E2EProfileRegistry { */ E2EProfile* get_default_profile(); + E2EProfileRegistry(const E2EProfileRegistry&) = delete; + E2EProfileRegistry& operator=(const E2EProfileRegistry&) = delete; + private: E2EProfileRegistry() = default; ~E2EProfileRegistry() = default; - E2EProfileRegistry(const E2EProfileRegistry&) = delete; - E2EProfileRegistry& operator=(const E2EProfileRegistry&) = delete; mutable platform::Mutex mutex_; std::unordered_map profiles_by_id_; diff --git a/include/platform/posix/net_impl.h b/include/platform/posix/net_impl.h index c1e24ed09d..d032801106 100644 --- a/include/platform/posix/net_impl.h +++ b/include/platform/posix/net_impl.h @@ -159,7 +159,7 @@ static inline int someip_set_socket_timeout(someip_socket_t fd, int optname, int timeout_ms) { struct timeval tv{}; tv.tv_sec = timeout_ms / 1000; - tv.tv_usec = (timeout_ms % 1000) * 1000; + tv.tv_usec = static_cast(timeout_ms % 1000) * 1000L; return ::setsockopt(fd, SOL_SOCKET, optname, &tv, sizeof(tv)); } diff --git a/include/someip/types.h b/include/someip/types.h index 44bd041c7a..75e430c796 100644 --- a/include/someip/types.h +++ b/include/someip/types.h @@ -76,11 +76,11 @@ struct MessageId { MessageId(uint16_t service, uint16_t method) : service_id(service), method_id(method) {} uint32_t to_uint32() const { - return (static_cast(service_id) << 16) | static_cast(method_id); + return (static_cast(service_id) << 16U) | static_cast(method_id); } static MessageId from_uint32(uint32_t value) { - return MessageId(static_cast(value >> 16), static_cast(value & 0xFFFFU)); + return MessageId(static_cast(value >> 16U), static_cast(value & 0xFFFFU)); } bool operator==(const MessageId& other) const { @@ -103,11 +103,11 @@ struct RequestId { RequestId(uint16_t client, uint16_t session) : client_id(client), session_id(session) {} uint32_t to_uint32() const { - return (static_cast(client_id) << 16) | static_cast(session_id); + return (static_cast(client_id) << 16U) | static_cast(session_id); } static RequestId from_uint32(uint32_t value) { - return RequestId(static_cast(value >> 16), static_cast(value & 0xFFFFU)); + return RequestId(static_cast(value >> 16U), static_cast(value & 0xFFFFU)); } bool operator==(const RequestId& other) const { diff --git a/include/transport/udp_transport.h b/include/transport/udp_transport.h index 9baa4b2179..b26eabf938 100644 --- a/include/transport/udp_transport.h +++ b/include/transport/udp_transport.h @@ -83,6 +83,10 @@ class UdpTransport : public ITransport { Result join_multicast_group(const std::string& multicast_address); Result leave_multicast_group(const std::string& multicast_address); + // Disable copy and assignment + UdpTransport(const UdpTransport&) = delete; + UdpTransport& operator=(const UdpTransport&) = delete; + private: Endpoint local_endpoint_; UdpTransportConfig config_; @@ -110,10 +114,6 @@ class UdpTransport : public ITransport { sockaddr_in create_sockaddr(const Endpoint& endpoint) const; Endpoint sockaddr_to_endpoint(const sockaddr_in& addr) const; bool is_multicast_address(const std::string& address) const; - - // Disable copy and assignment - UdpTransport(const UdpTransport&) = delete; - UdpTransport& operator=(const UdpTransport&) = delete; }; } // namespace someip::transport diff --git a/scripts/clang_tidy_to_allure.py b/scripts/clang_tidy_to_allure.py new file mode 100644 index 0000000000..72054f2f11 --- /dev/null +++ b/scripts/clang_tidy_to_allure.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python3 +"""Convert a clang-tidy report into Allure-compatible JUnit XML. + +Each clang-tidy check becomes a test suite, each unique warning becomes a +failing test case. The quality-gate result (pass/fail + counts) is emitted +as its own top-level test case. + +Usage: + python3 clang_tidy_to_allure.py [--threshold N] + +The output directory will contain a single JUnit XML file that the Allure +report workflow can ingest. +""" + +import argparse +import re +import xml.etree.ElementTree as ET +from collections import defaultdict +from pathlib import Path + + +def parse_report(report_path: str) -> tuple[list[tuple[str, int, str, str]], dict[str, int]]: + warnings: list[tuple[str, int, str, str]] = [] + summary: dict[str, int] = {} + + with open(report_path, encoding="utf-8", errors="replace") as f: + for line in f: + m = re.match(r"(.+?):(\d+):\d+: warning: (.+?) \[(.+?)\]", line.strip()) + if m: + filepath, lineno, message, check = ( + m.group(1), + int(m.group(2)), + m.group(3), + m.group(4), + ) + warnings.append((filepath, lineno, message, check)) + continue + + for key in ("Total Warnings", "Total Errors", "Total Issues", "Files with issues"): + if line.strip().startswith(f"{key}:"): + val = line.strip().split(":")[-1].strip() + if val.isdigit(): + summary[key] = int(val) + + return warnings, summary + + +def build_xml( + warnings: list[tuple[str, int, str, str]], + summary: dict[str, int], + threshold: int | None, +) -> ET.Element: + testsuites = ET.Element("testsuites") + + by_check: dict[str, list[tuple[str, int, str]]] = defaultdict(list) + for filepath, lineno, message, check in warnings: + by_check[check].append((filepath, lineno, message)) + + for check, items in sorted(by_check.items()): + unique = sorted(set(items)) + suite = ET.SubElement( + testsuites, + "testsuite", + name=f"clang-tidy/{check}", + tests=str(len(unique)), + failures=str(len(unique)), + ) + for filepath, lineno, message in unique: + tc = ET.SubElement( + suite, + "testcase", + classname=f"clang-tidy.{check}", + name=f"{filepath}:{lineno}", + ) + failure = ET.SubElement(tc, "failure", message=message) + failure.text = f"{filepath}:{lineno}: {message} [{check}]" + + total = summary.get("Total Issues", len(warnings)) + gate_suite = ET.SubElement( + testsuites, + "testsuite", + name="clang-tidy/quality-gate", + tests="1", + failures="0" if (threshold is None or total <= threshold) else "1", + ) + tc = ET.SubElement( + gate_suite, + "testcase", + classname="clang-tidy.quality-gate", + name=f"violations={total}" + (f" threshold={threshold}" if threshold is not None else ""), + ) + if threshold is not None and total > threshold: + failure = ET.SubElement( + tc, "failure", message=f"Violation count ({total}) exceeds threshold ({threshold})" + ) + failure.text = f"FAILED: {total} > {threshold}" + + return testsuites + + +def main() -> None: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("report", help="Path to clang-tidy-report.txt") + parser.add_argument("output_dir", help="Output directory for JUnit XML") + parser.add_argument("--threshold", type=int, default=None, help="Quality-gate threshold") + args = parser.parse_args() + + warnings, summary = parse_report(args.report) + xml_root = build_xml(warnings, summary, args.threshold) + + out = Path(args.output_dir) + out.mkdir(parents=True, exist_ok=True) + tree = ET.ElementTree(xml_root) + ET.indent(tree, space=" ") + tree.write(out / "clang-tidy-results.xml", encoding="unicode", xml_declaration=True) + print(f"Wrote {len(warnings)} warnings to {out / 'clang-tidy-results.xml'}") + + +if __name__ == "__main__": + main() diff --git a/src/e2e/e2e_crc.cpp b/src/e2e/e2e_crc.cpp index 99cc0cb253..5d2ef9c972 100644 --- a/src/e2e/e2e_crc.cpp +++ b/src/e2e/e2e_crc.cpp @@ -38,7 +38,7 @@ static constexpr uint8_t SAE_J1850_INIT = 0xFF; uint8_t calculate_crc8_sae_j1850(const std::vector& data) { uint32_t crc_reg = SAE_J1850_INIT; - for (uint8_t byte : data) { + for (const uint8_t byte : data) { crc_reg ^= static_cast(byte); for (int i = 0; i < 8; ++i) { if ((crc_reg & 0x80U) != 0) { @@ -59,7 +59,7 @@ static constexpr uint16_t ITU_X25_INIT = 0xFFFF; uint16_t calculate_crc16_itu_x25(const std::vector& data) { uint32_t crc_reg = ITU_X25_INIT; - for (uint8_t byte : data) { + for (const uint8_t byte : data) { crc_reg ^= static_cast(byte) << 8U; for (int i = 0; i < 8; ++i) { if ((crc_reg & 0x8000U) != 0) { @@ -105,8 +105,8 @@ uint32_t calculate_crc32(const std::vector& data) { uint32_t crc = CRC32_INIT; - for (uint8_t byte : data) { - uint32_t index = ((crc >> 24U) ^ static_cast(byte)) & 0xFFU; + for (const uint8_t byte : data) { + const uint32_t index = ((crc >> 24U) ^ static_cast(byte)) & 0xFFU; crc = (crc << 8U) ^ crc32_table[index]; } @@ -120,7 +120,7 @@ std::optional calculate_crc(const std::vector& data, size_t o } auto first = data.begin() + static_cast(offset); - std::vector slice(first, first + static_cast(length)); + const std::vector slice(first, first + static_cast(length)); switch (crc_type) { case 0: // SAE-J1850 (8-bit) diff --git a/src/e2e/e2e_profile_registry.cpp b/src/e2e/e2e_profile_registry.cpp index a3840cc9db..6d1a6a4910 100644 --- a/src/e2e/e2e_profile_registry.cpp +++ b/src/e2e/e2e_profile_registry.cpp @@ -13,7 +13,6 @@ #include "e2e/e2e_profile_registry.h" -#include "e2e/e2e_config.h" #include "platform/thread.h" #include diff --git a/src/e2e/e2e_profiles/standard_profile.cpp b/src/e2e/e2e_profiles/standard_profile.cpp index dd829c24a8..c7a913f3fe 100644 --- a/src/e2e/e2e_profiles/standard_profile.cpp +++ b/src/e2e/e2e_profiles/standard_profile.cpp @@ -83,8 +83,8 @@ class BasicE2EProfile : public E2EProfile { // which includes E2E header. However, we need to be careful - the actual length // in the message will be set by update_length() after we set the E2E header. // For now, calculate what the length will be: - size_t const e2e_size = E2EHeader::get_header_size(); - uint32_t length = 8 + e2e_size + static_cast(msg.get_payload().size()); + size_t const e2e_size = E2EHeader::get_header_size(); + const uint32_t length = 8 + e2e_size + static_cast(msg.get_payload().size()); uint32_t length_be = someip_htonl(length); crc_data.insert(crc_data.end(), reinterpret_cast(&length_be), reinterpret_cast(&length_be) + sizeof(uint32_t)); diff --git a/src/events/event_publisher.cpp b/src/events/event_publisher.cpp index fe123b5b0b..a1891eb7ce 100644 --- a/src/events/event_publisher.cpp +++ b/src/events/event_publisher.cpp @@ -32,6 +32,8 @@ namespace someip::events { +// NOLINTBEGIN(misc-include-cleaner) - platform::Mutex / platform::this_thread from platform/thread.h (IWYU false positives in impl). + /** * @brief Event Publisher implementation * @implements REQ_ARCH_001 @@ -208,6 +210,7 @@ class EventPublisherImpl : public transport::ITransportListener { std::vector get_registered_events() const { platform::ScopedLock const events_lock(events_mutex_); std::vector events; + events.reserve(registered_events_.size()); for (const auto& pair : registered_events_) { events.push_back(pair.first); @@ -295,7 +298,7 @@ class EventPublisherImpl : public transport::ITransportListener { } } - for (uint16_t eid : events_to_publish) { + for (const uint16_t eid : events_to_publish) { publish_event(eid, {}); } } @@ -419,4 +422,6 @@ EventPublisher::Statistics EventPublisher::get_statistics() const { return impl_->get_statistics(); } +// NOLINTEND(misc-include-cleaner) + } // namespace someip::events diff --git a/src/events/event_subscriber.cpp b/src/events/event_subscriber.cpp index 72a0efa307..d19b0cc4e5 100644 --- a/src/events/event_subscriber.cpp +++ b/src/events/event_subscriber.cpp @@ -33,6 +33,8 @@ namespace someip::events { +// NOLINTBEGIN(misc-include-cleaner) - platform::Mutex from platform/thread.h (IWYU false positives in impl). + /** * @brief Event Subscriber implementation * @implements REQ_ARCH_001 @@ -105,13 +107,13 @@ class EventSubscriberImpl : public transport::ITransportListener { // Store subscription platform::ScopedLock const subs_lock(subscriptions_mutex_); - std::string key = make_subscription_key(service_id, instance_id, eventgroup_id); + const std::string key = make_subscription_key(service_id, instance_id, eventgroup_id); subscriptions_[key] = std::move(sub_info); // Send subscription request via RPC (simplified - in real implementation, // this would use SD to find the service endpoint and send subscription) // For now, we'll assume the service is at a known endpoint - transport::Endpoint service_endpoint("127.0.0.1", 30500); // TODO: Get from SD + const transport::Endpoint service_endpoint("127.0.0.1", 30500); // TODO: Get from SD // Create subscription message (simplified) MessageId const msg_id(service_id, 0x0001); // Method ID for subscription @@ -124,7 +126,7 @@ class EventSubscriberImpl : public transport::ITransportListener { payload.push_back(static_cast(static_cast(eventgroup_id) & 0xFFU)); subscription_msg.set_payload(payload); - Result send_result = transport_->send_message(subscription_msg, service_endpoint); + const Result send_result = transport_->send_message(subscription_msg, service_endpoint); bool const success = (send_result == Result::SUCCESS); if (!success) { subscriptions_.erase(key); @@ -138,7 +140,7 @@ class EventSubscriberImpl : public transport::ITransportListener { } platform::ScopedLock const subs_lock(subscriptions_mutex_); - std::string key = make_subscription_key(service_id, instance_id, eventgroup_id); + const std::string key = make_subscription_key(service_id, instance_id, eventgroup_id); auto it = subscriptions_.find(key); if (it == subscriptions_.end()) { @@ -146,7 +148,7 @@ class EventSubscriberImpl : public transport::ITransportListener { } // Send unsubscription request - transport::Endpoint service_endpoint("127.0.0.1", 30500); // TODO: Get from SD + const transport::Endpoint service_endpoint("127.0.0.1", 30500); // TODO: Get from SD MessageId const msg_id(service_id, 0x0002); // Method ID for unsubscription Message unsubscription_msg(msg_id, RequestId(client_id_, 0x0002), @@ -158,7 +160,7 @@ class EventSubscriberImpl : public transport::ITransportListener { payload.push_back(static_cast(static_cast(eventgroup_id) & 0xFFU)); unsubscription_msg.set_payload(payload); - Result result = transport_->send_message(unsubscription_msg, service_endpoint); + const Result result = transport_->send_message(unsubscription_msg, service_endpoint); if (result != Result::SUCCESS) { // Log error or handle failure } @@ -177,11 +179,11 @@ class EventSubscriberImpl : public transport::ITransportListener { // Store callback for field response platform::ScopedLock const field_lock(field_requests_mutex_); - std::string key = make_field_key(service_id, instance_id, event_id); + const std::string key = make_field_key(service_id, instance_id, event_id); field_requests_[key] = std::move(callback); // Send field request - transport::Endpoint service_endpoint("127.0.0.1", 30500); // TODO: Get from SD + const transport::Endpoint service_endpoint("127.0.0.1", 30500); // TODO: Get from SD MessageId const msg_id(service_id, 0x0003); // Method ID for field request Message field_msg(msg_id, RequestId(client_id_, 0x0003), MessageType::REQUEST, @@ -214,6 +216,7 @@ class EventSubscriberImpl : public transport::ITransportListener { std::vector get_active_subscriptions() const { platform::ScopedLock const subs_lock(subscriptions_mutex_); std::vector result; + result.reserve(subscriptions_.size()); for (const auto& pair : subscriptions_) { result.push_back(pair.second.subscription); @@ -399,4 +402,6 @@ EventSubscriber::Statistics EventSubscriber::get_statistics() const { return impl_->get_statistics(); } +// NOLINTEND(misc-include-cleaner) + } // namespace someip::events diff --git a/src/rpc/rpc_client.cpp b/src/rpc/rpc_client.cpp index 7496bbb068..d68caa78a6 100644 --- a/src/rpc/rpc_client.cpp +++ b/src/rpc/rpc_client.cpp @@ -35,6 +35,8 @@ namespace someip::rpc { +// NOLINTBEGIN(misc-include-cleaner) - platform::Mutex / platform::this_thread from platform/thread.h (IWYU false positives in impl). + /** * @brief RPC Client implementation * @implements REQ_ARCH_001 @@ -115,9 +117,9 @@ class RpcClientImpl : public transport::ITransportListener { std::shared_ptr resp; std::atomic ready{false}; }; - auto state = std::make_shared(); + const auto state = std::make_shared(); - auto handle = call_method_async(service_id, method_id, parameters, + const auto handle = call_method_async(service_id, method_id, parameters, [state](const RpcResponse& response) { platform::ScopedLock lk(state->mtx); state->resp = std::make_shared(response); @@ -128,7 +130,7 @@ class RpcClientImpl : public transport::ITransportListener { return {RpcResult::INTERNAL_ERROR, {}, std::chrono::milliseconds(0)}; } - auto deadline = std::chrono::steady_clock::now() + const auto deadline = std::chrono::steady_clock::now() + std::chrono::milliseconds(timeout.response_timeout); while (!state->ready.load()) { auto now = std::chrono::steady_clock::now(); @@ -136,8 +138,8 @@ class RpcClientImpl : public transport::ITransportListener { cancel_call(handle); return {RpcResult::TIMEOUT, {}, timeout.response_timeout}; } - auto remaining = std::chrono::duration_cast(deadline - now); - auto sleep_time = std::min(remaining, std::chrono::milliseconds(1)); + const auto remaining = std::chrono::duration_cast(deadline - now); + const auto sleep_time = std::min(remaining, std::chrono::milliseconds(1)); platform::this_thread::sleep_for(sleep_time); } @@ -158,7 +160,7 @@ class RpcClientImpl : public transport::ITransportListener { } // Create session for this call - uint16_t session_id = session_manager_->create_session(client_id_); + const uint16_t session_id = session_manager_->create_session(client_id_); // Create request message MessageId const msg_id(service_id, method_id); @@ -181,7 +183,7 @@ class RpcClientImpl : public transport::ITransportListener { } // Send request - transport::Endpoint server_endpoint("127.0.0.1", 30490); // TODO: Make configurable + const transport::Endpoint server_endpoint("127.0.0.1", 30490); // TODO: Make configurable if (transport_->send_message(request, server_endpoint) != Result::SUCCESS) { platform::ScopedLock const lock(pending_calls_mutex_); pending_calls_.erase(handle); @@ -248,7 +250,7 @@ class RpcClientImpl : public transport::ITransportListener { it->second.service_id == message->get_service_id() && it->second.method_id == message->get_method_id()) { - RpcResult result = (message->is_success()) ? RpcResult::SUCCESS : RpcResult::INTERNAL_ERROR; + const RpcResult result = (message->is_success()) ? RpcResult::SUCCESS : RpcResult::INTERNAL_ERROR; recv_resp = RpcResponse(message->get_service_id(), message->get_method_id(), message->get_client_id(), message->get_session_id(), result); recv_resp.return_values = message->get_payload(); @@ -328,4 +330,6 @@ RpcClient::Statistics RpcClient::get_statistics() const { return impl_->get_statistics(); } +// NOLINTEND(misc-include-cleaner) + } // namespace someip::rpc diff --git a/src/rpc/rpc_server.cpp b/src/rpc/rpc_server.cpp index f0e6784967..74dd9df5f4 100644 --- a/src/rpc/rpc_server.cpp +++ b/src/rpc/rpc_server.cpp @@ -32,6 +32,8 @@ namespace someip::rpc { +// NOLINTBEGIN(misc-include-cleaner) - platform::Mutex from platform/thread.h (IWYU false positives in impl). + /** * @brief RPC Server implementation * @implements REQ_ARCH_001 @@ -86,7 +88,7 @@ class RpcServerImpl : public transport::ITransportListener { platform::ScopedLock const lock(methods_mutex_); // Check if already registered - bool already_exists = method_handlers_.count(method_id) > 0; + const bool already_exists = method_handlers_.count(method_id) > 0; if (!already_exists) { method_handlers_[method_id] = std::move(handler); } @@ -145,7 +147,7 @@ class RpcServerImpl : public transport::ITransportListener { // Process the method call std::vector output_params; - RpcResult result = handler(message->get_client_id(), message->get_session_id(), + const RpcResult result = handler(message->get_client_id(), message->get_session_id(), message->get_payload(), output_params); // Send response @@ -259,4 +261,6 @@ RpcServer::Statistics RpcServer::get_statistics() const { return impl_->get_statistics(); } +// NOLINTEND(misc-include-cleaner) + } // namespace someip::rpc diff --git a/src/sd/sd_client.cpp b/src/sd/sd_client.cpp index 843ac335d6..38f96e69e6 100644 --- a/src/sd/sd_client.cpp +++ b/src/sd/sd_client.cpp @@ -36,6 +36,8 @@ namespace someip::sd { +// NOLINTBEGIN(misc-include-cleaner) - platform::Mutex from platform/thread.h (IWYU false positives in impl). + namespace { std::shared_ptr create_sd_transport(const SdConfig& config) { @@ -144,7 +146,7 @@ class SdClientImpl : public transport::ITransportListener { } // Store callback for responses - uint32_t request_id = next_request_id_++; + const uint32_t request_id = next_request_id_++; { platform::ScopedLock const lock(pending_finds_mutex_); pending_finds_[request_id] = { @@ -391,7 +393,7 @@ class SdClientImpl : public transport::ITransportListener { ServiceAvailableCallback avail_cb; { platform::ScopedLock const lock(subscriptions_mutex_); - auto sub_it = service_subscriptions_.find(instance.service_id); + const auto sub_it = service_subscriptions_.find(instance.service_id); if (sub_it != service_subscriptions_.end() && sub_it->second.available_callback) { avail_cb = sub_it->second.available_callback; } @@ -440,7 +442,7 @@ class SdClientImpl : public transport::ITransportListener { ServiceUnavailableCallback unavail_cb; { platform::ScopedLock const lock(subscriptions_mutex_); - auto sub_it = service_subscriptions_.find(instance.service_id); + const auto sub_it = service_subscriptions_.find(instance.service_id); if (sub_it != service_subscriptions_.end() && sub_it->second.unavailable_callback) { unavail_cb = sub_it->second.unavailable_callback; } @@ -518,4 +520,6 @@ SdClient::Statistics SdClient::get_statistics() const { return impl_->get_statistics(); } +// NOLINTEND(misc-include-cleaner) + } // namespace someip::sd diff --git a/src/sd/sd_message.cpp b/src/sd/sd_message.cpp index 85bd48482b..2953c46127 100644 --- a/src/sd/sd_message.cpp +++ b/src/sd/sd_message.cpp @@ -293,8 +293,8 @@ bool IPv4EndpointOption::deserialize(const std::vector& data, size_t& o protocol_ = data[offset++]; // Port (2 bytes, network byte order) - uint16_t network_port = static_cast((static_cast(data[offset]) << 8U) | - static_cast(data[offset + 1])); + auto const network_port = static_cast((static_cast(data[offset]) << 8U) | + static_cast(data[offset + 1])); port_ = someip_ntohs(network_port); offset += 2; @@ -423,7 +423,7 @@ std::vector SdMessage::serialize() const { std::vector data; // Flags (1 byte) - ensure reserved bits 5-0 are zero (REQ_SD_013) - const uint8_t flags_to_send = static_cast(static_cast(flags_) & 0xC0U); + auto const flags_to_send = static_cast(static_cast(flags_) & 0xC0U); data.push_back(flags_to_send); // Reserved (3 bytes) @@ -444,7 +444,7 @@ std::vector SdMessage::serialize() const { auto entry_data = entry->serialize(); data.insert(data.end(), entry_data.begin(), entry_data.end()); } - const uint32_t entries_length = static_cast(data.size() - entries_start); + auto const entries_length = static_cast(data.size() - entries_start); // Back-fill Length of Entries Array data[entries_len_offset] = static_cast((entries_length >> 24U) & 0xFFU); @@ -465,7 +465,7 @@ std::vector SdMessage::serialize() const { auto option_data = option->serialize(); data.insert(data.end(), option_data.begin(), option_data.end()); } - const uint32_t options_length = static_cast(data.size() - options_start); + auto const options_length = static_cast(data.size() - options_start); // Back-fill Length of Options Array data[options_len_offset] = static_cast((options_length >> 24U) & 0xFFU); @@ -549,7 +549,7 @@ bool SdMessage::deserialize(const std::vector& data) { // Options start with length(2) + type(1) + reserved(1). // Peek at the type byte (offset + 2) to determine the option kind. const uint8_t type_byte = data[offset + 2]; - OptionType const option_type = static_cast(type_byte); + auto const option_type = static_cast(type_byte); std::unique_ptr option; if (option_type == OptionType::CONFIGURATION) { @@ -559,7 +559,7 @@ bool SdMessage::deserialize(const std::vector& data) { } else if (option_type == OptionType::IPV4_MULTICAST) { option = std::make_unique(); } else { - const uint16_t option_len = static_cast( + auto const option_len = static_cast( (static_cast(data[offset]) << 8U) | static_cast(data[offset + 1])); if (offset + 4 + option_len > options_end) { return false; diff --git a/src/sd/sd_server.cpp b/src/sd/sd_server.cpp index ce15bcaec7..6356bf6992 100644 --- a/src/sd/sd_server.cpp +++ b/src/sd/sd_server.cpp @@ -34,7 +34,6 @@ #include #include #include -#include #include #include @@ -244,7 +243,7 @@ class SdServerImpl : public transport::ITransportListener { client_port = static_cast(std::stoi(client_address.substr(colon_pos + 1))); } - transport::Endpoint client_endpoint(client_ip, client_port); + const transport::Endpoint client_endpoint(client_ip, client_port); // Create SOME/IP message for SD Message someip_message(MessageId(0xFFFF, SOMEIP_SD_METHOD_ID), @@ -260,6 +259,7 @@ class SdServerImpl : public transport::ITransportListener { std::vector get_offered_services() const { platform::ScopedLock const lock(offered_services_mutex_); std::vector result; + result.reserve(offered_services_.size()); for (const auto& service : offered_services_) { result.push_back(service.instance); diff --git a/src/someip/message.cpp b/src/someip/message.cpp index 83649f5e59..54d7ea10f9 100644 --- a/src/someip/message.cpp +++ b/src/someip/message.cpp @@ -86,7 +86,7 @@ Message::Message(Message&& other) noexcept message_type_(other.message_type_), return_code_(other.return_code_), payload_(std::move(other.payload_)), // Move the payload - e2e_header_(std::move(other.e2e_header_)), // Move E2E header + e2e_header_(other.e2e_header_), timestamp_(other.timestamp_) { // Invalidate the moved-from object (safety-critical design: moved-from messages are invalid) other.interface_version_ = 0xFF; @@ -120,7 +120,7 @@ Message& Message::operator=(Message&& other) noexcept { message_type_ = other.message_type_; return_code_ = other.return_code_; payload_ = std::move(other.payload_); // Move the payload - e2e_header_ = std::move(other.e2e_header_); // Move E2E header + e2e_header_ = other.e2e_header_; timestamp_ = other.timestamp_; // Invalidate the moved-from object diff --git a/src/transport/tcp_transport.cpp b/src/transport/tcp_transport.cpp index 4490c72664..def4275a59 100644 --- a/src/transport/tcp_transport.cpp +++ b/src/transport/tcp_transport.cpp @@ -20,7 +20,6 @@ #include "platform/net.h" #include "platform/thread.h" #include "someip/message.h" -#include "someip/types.h" #include "transport/endpoint.h" #include "transport/transport.h" @@ -434,14 +433,14 @@ void TcpTransport::receive_loop() { } std::vector buffer; - Result result = receive_data(connection_.socket_fd, buffer); + const Result result = receive_data(connection_.socket_fd, buffer); if (result == Result::SUCCESS && !buffer.empty()) { // Try to parse messages from buffer MessagePtr message; if (parse_message_from_buffer(buffer, message)) { platform::ScopedLock const lock(queue_mutex_); - message_queue_.push({message, connection_.remote_endpoint}); + message_queue_.emplace(message, connection_.remote_endpoint); connection_.update_activity(); if (auto* l = listener_.load(std::memory_order_acquire)) { diff --git a/src/transport/udp_transport.cpp b/src/transport/udp_transport.cpp index d6936ec0b6..c7e27fffbd 100644 --- a/src/transport/udp_transport.cpp +++ b/src/transport/udp_transport.cpp @@ -20,7 +20,6 @@ #include "platform/net.h" #include "platform/thread.h" #include "someip/message.h" -#include "someip/types.h" #include "transport/endpoint.h" #include "transport/transport.h" @@ -29,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -375,7 +373,7 @@ void UdpTransport::receive_loop() { while (running_) { Endpoint sender; size_t bytes_received = 0; - Result result = receive_data(buffer, sender, bytes_received); + const Result result = receive_data(buffer, sender, bytes_received); if (result == Result::SUCCESS && bytes_received > 0) { MessagePtr message = platform::allocate_message();