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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
...
4 changes: 2 additions & 2 deletions src/e2e/e2e_crc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ uint8_t calculate_crc8_sae_j1850(const std::vector<uint8_t>& 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;
Expand All @@ -60,7 +60,7 @@ uint16_t calculate_crc16_itu_x25(const std::vector<uint8_t>& data) {
for (uint8_t byte : data) {
crc ^= (static_cast<uint16_t>(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;
Expand Down
8 changes: 4 additions & 4 deletions src/e2e/e2e_profile_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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;

Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/e2e/e2e_protection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions src/events/event_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<std::chrono::milliseconds>(
auto const time_since_last = std::chrono::duration_cast<std::chrono::milliseconds>(
now - last_publish_times_[config.event_id]);

if (time_since_last >= config.cycle_time) {
Expand All @@ -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
}
Expand Down
11 changes: 6 additions & 5 deletions src/platform/freertos/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <task.h>

#include <atomic>
#include <cstdint>
#include <cstring>
#include <new>

Expand Down Expand Up @@ -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<char*>(msg);
auto* pool_start = static_cast<char*>(pool_buffer);
if (raw < pool_start || raw >= pool_start + POOL_SIZE * sizeof(someip::Message)) {
auto raw_addr = reinterpret_cast<std::uintptr_t>(msg);
auto pool_addr = reinterpret_cast<std::uintptr_t>(pool_buffer);
if (raw_addr < pool_addr || raw_addr >= pool_addr + POOL_SIZE * sizeof(someip::Message)) {
return;
}
size_t const byte_offset = static_cast<size_t>(raw - pool_start);
size_t const byte_offset = raw_addr - pool_addr;
if (byte_offset % sizeof(someip::Message) != 0) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform/threadx/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void ensure_pool_init() {
}

void release_message_impl(someip::Message* msg) {
if (!msg) {
if (msg == nullptr) {
return;
}

Expand Down
15 changes: 1 addition & 14 deletions src/someip/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_),
Expand Down
8 changes: 4 additions & 4 deletions src/tp/tp_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void TpManager::shutdown() {
}

bool TpManager::needs_segmentation(const Message& message) const {
std::vector<uint8_t> data = message.serialize();
std::vector<uint8_t> const data = message.serialize();
return data.size() > config_.max_segment_size;
}

Expand All @@ -71,7 +71,7 @@ TpResult TpManager::segment_message(const Message& message, uint32_t& transfer_i

// Segment the message
std::vector<TpSegment> segments;
TpResult result = segmenter_->segment_message(message, segments);
TpResult const result = segmenter_->segment_message(message, segments);

if (result != TpResult::SUCCESS) {
return result;
Expand Down Expand Up @@ -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<std::chrono::milliseconds>(
auto const elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
now - transfer.last_activity);

if (elapsed > config_.reassembly_timeout) {
Expand Down
19 changes: 11 additions & 8 deletions src/tp/tp_reassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ bool TpReassembler::parse_tp_header(const std::vector<uint8_t>& 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<uint32_t>(payload[16]) << 24) |
(static_cast<uint32_t>(payload[17]) << 16) |
(static_cast<uint32_t>(payload[18]) << 8) |
static_cast<uint32_t>(payload[19]);

// Extract offset (28 bits, divided by 4 to get byte offset)
uint32_t const offset_units = tp_header >> 4;
Expand Down Expand Up @@ -84,7 +87,7 @@ bool TpReassembler::process_segment(const TpSegment& segment, std::vector<uint8_
platform::ScopedLock const lock(buffers_mutex_);

TpReassemblyBuffer* buffer = find_or_create_buffer(segment);
if (!buffer) {
if (buffer == nullptr) {
return false;
}

Expand Down Expand Up @@ -176,7 +179,7 @@ bool TpReassembler::add_segment_to_buffer(TpReassemblyBuffer& buffer, const TpSe
header_overhead = 4; // TP header only for consecutive/last segments
}

size_t actual_payload_bytes = segment.payload.size() > header_overhead
size_t const actual_payload_bytes = segment.payload.size() > header_overhead
? segment.payload.size() - header_overhead
: 0;

Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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<std::chrono::milliseconds>(
auto const elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
now - it->second->start_time);

if (elapsed > config.reassembly_timeout) {
Expand Down
17 changes: 10 additions & 7 deletions src/tp/tp_segmenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ TpResult TpSegmenter::create_multi_segments(const Message& message,
const std::vector<uint8_t>& payload,
std::vector<TpSegment>& segments) {

uint32_t total_length = static_cast<uint32_t>(payload.size());
uint32_t const total_length = static_cast<uint32_t>(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;
Expand All @@ -101,8 +101,10 @@ TpResult TpSegmenter::create_multi_segments(const Message& message,
std::vector<uint8_t> 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<size_t>(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<size_t>(total_length));
header.insert(header.end(), payload.begin(),
payload.begin() + static_cast<std::ptrdiff_t>(first_payload_size));
Expand Down Expand Up @@ -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<uint16_t>(
std::min(static_cast<uint32_t>(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<uint16_t>(
std::min(segment_capacity, remaining_bytes));

// Create segment with TP header
std::vector<uint8_t> segment_data;
Expand Down
27 changes: 12 additions & 15 deletions src/transport/endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {
Expand Down Expand Up @@ -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<unsigned char>(address[pos]))) {
if (std::isdigit(static_cast<unsigned char>(address[pos])) == 0) {
return false;
}

size_t start = pos;
while (pos < address.size() && std::isdigit(static_cast<unsigned char>(address[pos]))) {
size_t const start = pos;
while (pos < address.size() && std::isdigit(static_cast<unsigned char>(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;
}
Expand Down Expand Up @@ -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<unsigned char>(c)) && c != ':') {
for (char const c : address) {
if (std::isxdigit(static_cast<unsigned char>(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;
}
Expand Down Expand Up @@ -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;
Expand Down
Loading