diff --git a/.clang-tidy b/.clang-tidy index 09c386ce0..3b50a351b 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -73,6 +73,12 @@ CheckOptions: value: lower_case - key: readability-identifier-naming.ConstantCase value: UPPER_CASE + - key: readability-identifier-naming.LocalConstantCase + value: lower_case + - key: readability-identifier-naming.LocalConstantPointerCase + value: lower_case + - key: readability-identifier-naming.StaticConstantCase + value: UPPER_CASE - key: readability-identifier-naming.NamespaceCase value: lower_case - key: readability-identifier-naming.EnumCase @@ -83,6 +89,8 @@ CheckOptions: value: lower_case - key: readability-identifier-naming.PrivateMemberSuffix value: '_' + - key: readability-identifier-naming.ProtectedMemberSuffix + value: '_' - key: readability-identifier-naming.EnumConstantCase value: UPPER_CASE ... diff --git a/src/e2e/e2e_crc.cpp b/src/e2e/e2e_crc.cpp index fe60b33c3..06e8f0cac 100644 --- a/src/e2e/e2e_crc.cpp +++ b/src/e2e/e2e_crc.cpp @@ -39,7 +39,7 @@ uint8_t calculate_crc8_sae_j1850(const std::vector& data) { for (uint8_t byte : data) { crc ^= byte; for (int i = 0; i < 8; ++i) { - if (crc & 0x80) { + if ((crc & 0x80) != 0) { crc = (crc << 1) ^ SAE_J1850_POLY; } else { crc <<= 1; @@ -60,7 +60,7 @@ uint16_t calculate_crc16_itu_x25(const std::vector& data) { for (uint8_t byte : data) { crc ^= (static_cast(byte) << 8); for (int i = 0; i < 8; ++i) { - if (crc & 0x8000) { + if ((crc & 0x8000) != 0) { crc = (crc << 1) ^ ITU_X25_POLY; } else { crc <<= 1; diff --git a/src/e2e/e2e_profile_registry.cpp b/src/e2e/e2e_profile_registry.cpp index 25978488b..bcabc8a7b 100644 --- a/src/e2e/e2e_profile_registry.cpp +++ b/src/e2e/e2e_profile_registry.cpp @@ -37,8 +37,8 @@ bool E2EProfileRegistry::register_profile(E2EProfilePtr profile) { platform::ScopedLock const lock(mutex_); - uint32_t profile_id = profile->get_profile_id(); - std::string profile_name = profile->get_profile_name(); + uint32_t const profile_id = profile->get_profile_id(); + std::string const profile_name = profile->get_profile_name(); // Check if profile ID already exists if (profiles_by_id_.find(profile_id) != profiles_by_id_.end()) { @@ -51,7 +51,7 @@ bool E2EProfileRegistry::register_profile(E2EProfilePtr profile) { } // Register profile - E2EProfile* raw_ptr = profile.get(); + E2EProfile* const raw_ptr = profile.get(); profiles_by_id_[profile_id] = std::move(profile); profiles_by_name_[profile_name] = raw_ptr; @@ -93,7 +93,7 @@ bool E2EProfileRegistry::unregister_profile(uint32_t profile_id) { } // Remove from name map - std::string profile_name = it->second->get_profile_name(); + std::string const profile_name = it->second->get_profile_name(); profiles_by_name_.erase(profile_name); // Remove from ID map diff --git a/src/e2e/e2e_protection.cpp b/src/e2e/e2e_protection.cpp index 642b4687c..fa031c83a 100644 --- a/src/e2e/e2e_protection.cpp +++ b/src/e2e/e2e_protection.cpp @@ -32,16 +32,16 @@ Result E2EProtection::protect(Message& message, const E2EConfig& config) { E2EProfile* profile = registry.get_profile(config.profile_id); // If profile not found by ID, try by name - if (!profile) { + if (profile == nullptr) { profile = registry.get_profile(config.profile_name); } // If still not found, use default profile - if (!profile) { + if (profile == nullptr) { profile = registry.get_default_profile(); } - if (!profile) { + if (profile == nullptr) { return Result::NOT_INITIALIZED; // Basic profile not initialized } @@ -62,16 +62,16 @@ Result E2EProtection::validate(const Message& message, const E2EConfig& config) E2EProfile* profile = registry.get_profile(config.profile_id); // If profile not found by ID, try by name - if (!profile) { + if (profile == nullptr) { profile = registry.get_profile(config.profile_name); } // If still not found, use default profile - if (!profile) { + if (profile == nullptr) { profile = registry.get_default_profile(); } - if (!profile) { + if (profile == nullptr) { return Result::NOT_INITIALIZED; // Basic profile not initialized } diff --git a/src/events/event_publisher.cpp b/src/events/event_publisher.cpp index 4a5fc1c3b..974d116ea 100644 --- a/src/events/event_publisher.cpp +++ b/src/events/event_publisher.cpp @@ -87,7 +87,7 @@ class EventPublisherImpl : public transport::ITransportListener { platform::ScopedLock const events_lock(events_mutex_); // Check if already registered - bool already_exists = registered_events_.count(config.event_id) > 0; + bool const already_exists = registered_events_.count(config.event_id) > 0; if (!already_exists) { registered_events_[config.event_id] = config; } @@ -277,7 +277,7 @@ class EventPublisherImpl : public transport::ITransportListener { if (config.notification_type == NotificationType::PERIODIC && config.cycle_time.count() > 0) { - auto time_since_last = std::chrono::duration_cast( + auto const time_since_last = std::chrono::duration_cast( now - last_publish_times_[config.event_id]); if (time_since_last >= config.cycle_time) { @@ -303,7 +303,7 @@ class EventPublisherImpl : public transport::ITransportListener { MessageType::NOTIFICATION, ReturnCode::E_OK); someip_message.set_payload(notification.event_data); - Result result = transport_->send_message(someip_message, client_endpoint); + Result const result = transport_->send_message(someip_message, client_endpoint); if (result != Result::SUCCESS) { // Log error or handle failure } diff --git a/src/platform/freertos/memory.cpp b/src/platform/freertos/memory.cpp index 1dd56f44a..c69f5baa8 100644 --- a/src/platform/freertos/memory.cpp +++ b/src/platform/freertos/memory.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -60,16 +61,16 @@ void ensure_pool_init() { } void release_message_impl(someip::Message* msg) { - if (!msg) { + if (msg == nullptr) { return; } - auto* raw = reinterpret_cast(msg); - auto* pool_start = static_cast(pool_buffer); - if (raw < pool_start || raw >= pool_start + POOL_SIZE * sizeof(someip::Message)) { + auto raw_addr = reinterpret_cast(msg); + auto pool_addr = reinterpret_cast(pool_buffer); + if (raw_addr < pool_addr || raw_addr >= pool_addr + POOL_SIZE * sizeof(someip::Message)) { return; } - size_t const byte_offset = static_cast(raw - pool_start); + size_t const byte_offset = raw_addr - pool_addr; if (byte_offset % sizeof(someip::Message) != 0) { return; } diff --git a/src/platform/threadx/memory.cpp b/src/platform/threadx/memory.cpp index 5dd9eb5ce..4dc1f832d 100644 --- a/src/platform/threadx/memory.cpp +++ b/src/platform/threadx/memory.cpp @@ -71,7 +71,7 @@ void ensure_pool_init() { } void release_message_impl(someip::Message* msg) { - if (!msg) { + if (msg == nullptr) { return; } diff --git a/src/someip/message.cpp b/src/someip/message.cpp index 6a21a343a..a6e45e3c1 100644 --- a/src/someip/message.cpp +++ b/src/someip/message.cpp @@ -64,20 +64,7 @@ Message::Message(MessageId message_id, RequestId request_id, update_length(); } -// NOLINTNEXTLINE(modernize-use-equals-default) - explicit copy for clarity -Message::Message(const Message& other) - : message_id_(other.message_id_), - length_(other.length_), - request_id_(other.request_id_), - protocol_version_(other.protocol_version_), - interface_version_(other.interface_version_), - message_type_(other.message_type_), - return_code_(other.return_code_), - payload_(other.payload_), - e2e_header_(other.e2e_header_), - timestamp_(other.timestamp_) { - // Length is copied as-is for copy constructor -} +Message::Message(const Message& other) = default; Message::Message(Message&& other) noexcept : message_id_(other.message_id_), diff --git a/src/tp/tp_manager.cpp b/src/tp/tp_manager.cpp index 0f038ad76..c5e00a51b 100644 --- a/src/tp/tp_manager.cpp +++ b/src/tp/tp_manager.cpp @@ -45,7 +45,7 @@ void TpManager::shutdown() { } bool TpManager::needs_segmentation(const Message& message) const { - std::vector data = message.serialize(); + std::vector const data = message.serialize(); return data.size() > config_.max_segment_size; } @@ -71,7 +71,7 @@ TpResult TpManager::segment_message(const Message& message, uint32_t& transfer_i // Segment the message std::vector segments; - TpResult result = segmenter_->segment_message(message, segments); + TpResult const result = segmenter_->segment_message(message, segments); if (result != TpResult::SUCCESS) { return result; @@ -198,11 +198,11 @@ void TpManager::process_timeouts() { cb = completion_callback_; - auto now = std::chrono::steady_clock::now(); + auto const now = std::chrono::steady_clock::now(); for (auto it = active_transfers_.begin(); it != active_transfers_.end(); ) { TpTransfer& transfer = it->second; - auto elapsed = std::chrono::duration_cast( + auto const elapsed = std::chrono::duration_cast( now - transfer.last_activity); if (elapsed > config_.reassembly_timeout) { diff --git a/src/tp/tp_reassembler.cpp b/src/tp/tp_reassembler.cpp index c4662ae14..5558bf4bd 100644 --- a/src/tp/tp_reassembler.cpp +++ b/src/tp/tp_reassembler.cpp @@ -49,8 +49,11 @@ bool TpReassembler::parse_tp_header(const std::vector& payload, } // TP header starts at offset 16 (after SOME/IP header) - uint32_t tp_header = (payload[16] << 24) | (payload[17] << 16) | - (payload[18] << 8) | payload[19]; + uint32_t const tp_header = + (static_cast(payload[16]) << 24) | + (static_cast(payload[17]) << 16) | + (static_cast(payload[18]) << 8) | + static_cast(payload[19]); // Extract offset (28 bits, divided by 4 to get byte offset) uint32_t const offset_units = tp_header >> 4; @@ -84,7 +87,7 @@ bool TpReassembler::process_segment(const TpSegment& segment, std::vector header_overhead + size_t const actual_payload_bytes = segment.payload.size() > header_overhead ? segment.payload.size() - header_overhead : 0; @@ -252,8 +255,8 @@ bool TpReassembler::get_reassembly_progress(uint32_t message_id, uint32_t& recei // Count received bytes received_bytes = 0; - for (size_t i = 0; i < buffer.received_segments.size(); ++i) { - if (buffer.received_segments[i]) { + for (bool received : buffer.received_segments) { + if (received) { received_bytes += config.max_segment_size; // Approximate } } @@ -302,10 +305,10 @@ void TpReassembler::cleanup_completed_buffers() { } void TpReassembler::cleanup_timed_out_buffers(const TpConfig& config) { - auto now = std::chrono::steady_clock::now(); + auto const now = std::chrono::steady_clock::now(); for (auto it = reassembly_buffers_.begin(); it != reassembly_buffers_.end(); ) { - auto elapsed = std::chrono::duration_cast( + auto const elapsed = std::chrono::duration_cast( now - it->second->start_time); if (elapsed > config.reassembly_timeout) { diff --git a/src/tp/tp_segmenter.cpp b/src/tp/tp_segmenter.cpp index c86901988..8e83afa72 100644 --- a/src/tp/tp_segmenter.cpp +++ b/src/tp/tp_segmenter.cpp @@ -82,9 +82,9 @@ TpResult TpSegmenter::create_multi_segments(const Message& message, const std::vector& payload, std::vector& segments) { - uint32_t total_length = static_cast(payload.size()); + uint32_t const total_length = static_cast(payload.size()); uint16_t payload_offset = 0; // Offset into the payload data - uint8_t const sequence_number = next_sequence_number_++; + uint8_t const sequence_number = next_sequence_number_; // Create a copy of the message with TP flag added to message type Message tp_message = message; @@ -101,8 +101,10 @@ TpResult TpSegmenter::create_multi_segments(const Message& message, std::vector header = tp_message.serialize(); header.resize(16); // Keep only header (16 bytes) - // Add first part of payload (accounting for TP header) - size_t first_payload_size = std::min(static_cast(config_.max_segment_size - 16 - 4), + size_t const first_overhead = 16 + 4; + size_t const first_capacity = config_.max_segment_size > first_overhead + ? config_.max_segment_size - first_overhead : 0; + size_t const first_payload_size = std::min(first_capacity, static_cast(total_length)); header.insert(header.end(), payload.begin(), payload.begin() + static_cast(first_payload_size)); @@ -141,9 +143,10 @@ TpResult TpSegmenter::create_multi_segments(const Message& message, segment.header.segment_offset = payload_offset; segment.header.sequence_number = sequence_number; - // Calculate payload size for this segment (accounting for TP header) - uint16_t payload_size = static_cast( - std::min(static_cast(config_.max_segment_size - 4), remaining_bytes)); + uint32_t const segment_capacity = config_.max_segment_size > 4 + ? config_.max_segment_size - 4 : 0; + uint16_t const payload_size = static_cast( + std::min(segment_capacity, remaining_bytes)); // Create segment with TP header std::vector segment_data; diff --git a/src/transport/endpoint.cpp b/src/transport/endpoint.cpp index ec864912e..9d106817b 100644 --- a/src/transport/endpoint.cpp +++ b/src/transport/endpoint.cpp @@ -38,10 +38,7 @@ Endpoint::Endpoint(const std::string& address, uint16_t port, TransportProtocol : address_(address), port_(port), protocol_(protocol) { } -// NOLINTNEXTLINE(modernize-use-equals-default) - explicit copy for clarity -Endpoint::Endpoint(const Endpoint& other) - : address_(other.address_), port_(other.port_), protocol_(other.protocol_) { -} +Endpoint::Endpoint(const Endpoint& other) = default; Endpoint::Endpoint(Endpoint&& other) noexcept : address_(std::move(other.address_)), port_(other.port_), protocol_(other.protocol_) { @@ -138,21 +135,21 @@ bool Endpoint::is_valid_ipv4(const std::string& address) const { size_t pos = 0; while (pos < address.size() && octets < 4) { - if (!std::isdigit(static_cast(address[pos]))) { + if (std::isdigit(static_cast(address[pos])) == 0) { return false; } - size_t start = pos; - while (pos < address.size() && std::isdigit(static_cast(address[pos]))) { + size_t const start = pos; + while (pos < address.size() && std::isdigit(static_cast(address[pos])) != 0) { ++pos; } - size_t digit_len = pos - start; + size_t const digit_len = pos - start; if (digit_len == 0 || digit_len > 3) { return false; } - int val = std::atoi(address.substr(start, digit_len).c_str()); + int const val = std::atoi(address.substr(start, digit_len).c_str()); if (val < 0 || val > 255) { return false; } @@ -180,14 +177,14 @@ bool Endpoint::is_valid_ipv6(const std::string& address) const { return false; } - for (char c : address) { - if (!std::isxdigit(static_cast(c)) && c != ':') { + for (char const c : address) { + if (std::isxdigit(static_cast(c)) == 0 && c != ':') { return false; } } - size_t double_colon = address.find("::"); - bool has_double_colon = (double_colon != std::string::npos); + size_t const double_colon = address.find("::"); + bool const has_double_colon = (double_colon != std::string::npos); if (has_double_colon && address.find("::", double_colon + 2) != std::string::npos) { return false; } @@ -262,12 +259,12 @@ bool Endpoint::is_multicast_ipv4(const std::string& address) const { } // Extract first octet - size_t first_dot = address.find('.'); + size_t const first_dot = address.find('.'); if (first_dot == std::string::npos) { return false; } - int first_octet = std::stoi(address.substr(0, first_dot)); + int const first_octet = std::stoi(address.substr(0, first_dot)); // IPv4 multicast range: 224.0.0.0 to 239.255.255.255 return first_octet >= 224 && first_octet <= 239;