Skip to content

fix: remediate batch 5 clang-tidy violations#230

Merged
vtz merged 2 commits intomainfrom
feat/clang-tidy-batch5
Apr 13, 2026
Merged

fix: remediate batch 5 clang-tidy violations#230
vtz merged 2 commits intomainfrom
feat/clang-tidy-batch5

Conversation

@vtz
Copy link
Copy Markdown
Owner

@vtz vtz commented Apr 13, 2026

Summary

Fifth batch of clang-tidy remediations eliminating the largest remaining violation category — signed bitwise operations — across 19 files.

Changes by category

Signed bitwise (hicpp-signed-bitwise, ~349 fixes)

  • Cast uint8_t/uint16_t to uint32_t before bitwise shifts to prevent UB from signed int promotion
  • Add U suffix to hex literals used with bitwise operators (0xFF0xFFU, etc.)
  • Fixed across all modules: sd_message (119), types.h (102), tp_segmenter (25), sd_message.h (24), net_impl headers (18), serializer (16), e2e_crc (16), event_subscriber (9), tcp_transport (8), standard_profile (6), tp_reassembler (5), tp_manager (1)

Explicit conversions (5 fixes)

  • hicpp-explicit-conversions: Add explicit to single-argument Pimpl constructors (event_subscriber, rpc_client, rpc_server, sd_client, sd_server)

Qualified auto (3 fixes)

  • readability-qualified-auto: Use const auto* for pointer declarations in serializer

Error handling (1 fix)

  • cert-err34-c: Replace atoi with strtol in endpoint IPv4 validation

Test plan

  • All existing tests pass (Host, FreeRTOS, ThreadX, Zephyr, Windows)
  • Clang-tidy quality gate passes
  • No regressions in cross-compilation (ARM Cortex-M4)

Ref: #222

Made with Cursor

Summary by CodeRabbit

  • Refactor
    • Standardized integer type handling with explicit casting in bitwise operations across multiple modules.
    • Updated several constructor declarations to include the explicit keyword.
    • Applied unsigned literal suffixes and widened type conversions in bit-manipulation expressions throughout the codebase.

Signed-bitwise (hicpp-signed-bitwise, ~349 fixes):
- Cast uint8_t/uint16_t to uint32_t before bitwise shifts to
  prevent UB from signed int promotion
- Add U suffix to hex literals used with bitwise operators
- Fix across all modules: sd_message, types.h, e2e_crc,
  tp_segmenter, tp_reassembler, serializer, tcp_transport,
  event_subscriber, net_impl (posix/zephyr/lwip)

Explicit conversions (5 fixes):
- Add explicit to single-argument Pimpl constructors

Qualified auto (3 fixes):
- Use const auto* for pointer declarations in serializer

Error handling (1 fix):
- Replace atoi with strtol in endpoint validation

Made-with: Cursor
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 13, 2026

Warning

Rate limit exceeded

@vtz has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 52 minutes and 11 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 52 minutes and 11 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 07cf92dc-445e-4596-9967-d4c1ecdeb27e

📥 Commits

Reviewing files that changed from the base of the PR and between 3716a17 and 3865dee.

📒 Files selected for processing (3)
  • include/tp/tp_segmenter.h
  • src/e2e/e2e_profiles/standard_profile.cpp
  • src/tp/tp_segmenter.cpp
📝 Walkthrough

Walkthrough

The PR systematically adds explicit type casting, unsigned literal suffixes (e.g., U, ULL), and explicit constructor declarations across platform implementations, core types, serialization, and protocol modules. These changes enhance type safety in bitwise operations and prevent implicit conversions without altering functional behavior or control flow.

Changes

Cohort / File(s) Summary
Platform Network Implementations
include/platform/lwip/net_impl.h, include/platform/posix/net_impl.h, include/platform/zephyr/net_impl.h
Updated someip_set_nonblocking and someip_set_blocking to use explicit unsigned int casts for bitwise operations on O_NONBLOCK flags, then cast results back to int for fcntl/zsock_fcntl calls.
SOME/IP Core Types
include/someip/types.h
Added explicit uint32_t casts in MessageId::to_uint32() and RequestId::to_uint32() before OR-combining shifted bits; updated from_uint32() methods to use 0xFFFFU (unsigned literal) in mask operations.
SD Message Protocol
include/sd/sd_message.h
Updated flag-checking/setting methods (is_reboot(), is_unicast(), set_reboot(), set_unicast()) to cast flags_ to uint32_t before bitwise operations and back to uint8_t for storage.
CRC and E2E Profiles
src/e2e/e2e_crc.cpp, src/e2e/e2e_profiles/standard_profile.cpp
Reworked CRC-8/16/32 arithmetic to use wider uint32_t accumulators with explicit masking (& 0xFFU, & 0xFFFFU); applied unsigned literal suffixes to shift/bitmask constants; updated freshness computation and CRC validation masking in profile validation.
Event and RPC Implementations
src/events/event_subscriber.cpp, src/rpc/rpc_client.cpp, src/rpc/rpc_server.cpp
Added explicit keyword to constructors; updated ID byte packing in subscribe_eventgroup and unsubscribe_eventgroup to use uint32_t casts with unsigned literal suffixes before static_cast<uint8_t> for payload bytes.
SD Message Serialization
src/sd/sd_message.cpp, src/sd/sd_client.cpp, src/sd/sd_server.cpp
Applied explicit uint32_t casts and unsigned literals (U suffixes) to bit-shift and mask operations in binary serialization/deserialization of options, entries, and message fields; added explicit to SdClientImpl and SdServerImpl constructors.
Transport Layer
src/tp/tp_manager.cpp, src/tp/tp_reassembler.cpp, src/tp/tp_segmenter.cpp, src/transport/endpoint.cpp, src/transport/tcp_transport.cpp
Updated TP header construction/parsing to use explicit unsigned literals in shift operations; replaced std::atoi with std::strtol in IPv4 parsing; added uint32_t casts and unsigned suffixes to big-endian field assembly in TCP transport.
Serialization Utilities
src/serialization/serializer.cpp
Changed pointer types from auto to const auto* in append_be_uint16/32/64; added U suffix to shift constants (e.g., 56U, 8U) in big-endian conversion logic without altering computed values.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 Hops of safety, bounds so tight,
Unsigned casts in morning light,
Explicit keywords guard the way,
No sneaky conversions here to play!
Type-safe bits in every place,
Rabbit's refactor—swift and graceful.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 53.70% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main purpose of the PR: remediating clang-tidy violations in batch 5, which aligns with the comprehensive changes across 19 files addressing signed bitwise operations and other code quality issues.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/clang-tidy-batch5

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/e2e/e2e_profiles/standard_profile.cpp`:
- Line 269: The code narrows config.freshness_timeout_ms (uint32_t) to uint16_t
without validation, risking truncation before computing freshness_diff; add a
bounds check on config.freshness_timeout_ms at the point where timeout_units is
computed (or earlier during E2EConfig init) and handle out-of-range values
explicitly (e.g., clamp to 0xFFFF, return/log an error, or reject the config)
before casting to uint16_t; ensure the check uses the same constant 0xFFFFU and
update the logic around freshness_diff/timeout_units to rely on the validated
value (symbols to update: config.freshness_timeout_ms, timeout_units,
freshness_diff).

In `@src/tp/tp_segmenter.cpp`:
- Around line 160-164: The TP header builder uses a uint16_t offset which can
overflow for messages >65,535 bytes; update the offset/payload_offset parameter
type in serialize_tp_header (and its declaration in include/tp/tp_segmenter.h)
from uint16_t to uint32_t, adjust any local counters (e.g.,
payload_offset/counter variables used in segment loop) to uint32_t, ensure
offset_units is computed from that uint32_t and masked/shifted into the 32-bit
tp_header safely (preserve the (offset_units << 4) | flags construction but
operate on 32-bit values and cast bytes when pushing into segment_data), and
re-evaluate the 28-bit overflow check logic so it now works against the uint32_t
offset type.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: bf94f11b-1112-49b4-b49c-beb032fda4c3

📥 Commits

Reviewing files that changed from the base of the PR and between fded7d5 and 3716a17.

📒 Files selected for processing (19)
  • include/platform/lwip/net_impl.h
  • include/platform/posix/net_impl.h
  • include/platform/zephyr/net_impl.h
  • include/sd/sd_message.h
  • include/someip/types.h
  • src/e2e/e2e_crc.cpp
  • src/e2e/e2e_profiles/standard_profile.cpp
  • src/events/event_subscriber.cpp
  • src/rpc/rpc_client.cpp
  • src/rpc/rpc_server.cpp
  • src/sd/sd_client.cpp
  • src/sd/sd_message.cpp
  • src/sd/sd_server.cpp
  • src/serialization/serializer.cpp
  • src/tp/tp_manager.cpp
  • src/tp/tp_reassembler.cpp
  • src/tp/tp_segmenter.cpp
  • src/transport/endpoint.cpp
  • src/transport/tcp_transport.cpp

Comment thread src/e2e/e2e_profiles/standard_profile.cpp
Comment thread src/tp/tp_segmenter.cpp
- Clamp freshness_timeout_ms to 0xFFFF before narrowing to uint16_t
  to prevent silent truncation for large timeout values
- Widen payload_offset and serialize_tp_header offset parameter from
  uint16_t to uint32_t to support messages larger than 65535 bytes
  (the whole purpose of TP segmentation)

Made-with: Cursor
@vtz vtz merged commit a8879fe into main Apr 13, 2026
77 of 78 checks passed
@vtz vtz deleted the feat/clang-tidy-batch5 branch April 13, 2026 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant