Skip to content

fix: remediate batch 3 clang-tidy violations#228

Merged
vtz merged 3 commits intomainfrom
feat/clang-tidy-batch3
Apr 13, 2026
Merged

fix: remediate batch 3 clang-tidy violations#228
vtz merged 3 commits intomainfrom
feat/clang-tidy-batch3

Conversation

@vtz
Copy link
Copy Markdown
Owner

@vtz vtz commented Apr 13, 2026

Summary

Third batch of clang-tidy remediations targeting naming config, explicit bool conversions, const-correctness, and code modernization across 12 files.

Also includes the std::uintptr_t fix from PR #227 review.

Changes by category

Config (eliminates ~160 false-positive naming warnings)

  • LocalConstantCase: lower_case — stops flagging local const variables like lock guards
  • LocalConstantPointerCase: lower_case — same for local const pointers
  • ProtectedMemberSuffix: '_' — matches the existing private member convention
  • StaticConstantCase: UPPER_CASE — explicitly set for file-scope static consts

FreeRTOS pool fix (from PR #227 review)

  • Use std::uintptr_t for pool ownership bounds checks to avoid UB from comparing unrelated pointers

Readability (17 fixes)

  • readability-implicit-bool-conversion: explicit != nullptr / != 0 comparisons (e2e_crc, e2e_protection, freertos/memory, threadx/memory, tp_reassembler, endpoint)
  • hicpp-use-equals-default: trivial copy constructors for Message and Endpoint
  • modernize-loop-convert: range-based for in tp_reassembler

Const-correctness (~25 fixes)

  • Added const to local variables that are never modified (endpoint, tp_manager, tp_reassembler, tp_segmenter, e2e_profile_registry, event_publisher)

Test plan

  • All existing tests pass (Host, FreeRTOS, ThreadX, Zephyr, Windows)
  • Clang-tidy quality gate passes (expect ~160 fewer warnings from config)
  • No regressions in cross-compilation (ARM Cortex-M4)

Ref: #222

Made with Cursor

Summary by CodeRabbit

  • Chores

    • Updated build configuration and code formatting standards for improved consistency and maintainability.
  • Refactor

    • Simplified object copy constructors using compiler defaults; enhanced null pointer checks throughout the codebase for improved code clarity and correctness.

vtz added 2 commits April 13, 2026 12:48
Replace char* relational comparisons with std::uintptr_t integer
comparisons to avoid undefined behavior when checking whether a
pointer belongs to the pool buffer (comparing pointers to unrelated
objects is UB per the standard).

Ref: #227 (comment)
Made-with: Cursor
Config:
- Add LocalConstantCase/LocalConstantPointerCase (lower_case) to
  stop false-flagging local const variables like lock guards
- Add ProtectedMemberSuffix ('_') matching the private convention
- Add StaticConstantCase (UPPER_CASE) explicitly

Readability:
- Make implicit bool conversions explicit (14 sites across e2e,
  platform, transport, and tp modules)
- Use = default for trivial copy constructors (Message, Endpoint)
- Convert iterator loop to range-based for (tp_reassembler)

Const-correctness:
- Add const to ~25 local variables that are never modified
  (endpoint, tp_manager, tp_reassembler, tp_segmenter,
  e2e_profile_registry, event_publisher)

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 48 minutes and 58 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 48 minutes and 58 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: cbf55452-37da-4fc6-afec-016e0ba38b2a

📥 Commits

Reviewing files that changed from the base of the PR and between 3f36945 and 02afbb6.

📒 Files selected for processing (2)
  • src/tp/tp_reassembler.cpp
  • src/tp/tp_segmenter.cpp
📝 Walkthrough

Walkthrough

This PR applies consistent code-style improvements across the codebase: expanding .clang-tidy naming rules for constants and member suffixes, adding const qualifiers to local variables throughout multiple subsystems, replacing implicit boolean conditions with explicit comparisons against nullptr or 0, and converting custom copy constructors to compiler-generated defaults where semantics permit.

Changes

Cohort / File(s) Summary
Clang-Tidy Configuration
.clang-tidy
Extended readability-identifier-naming rules with local constant casing (LocalConstantCase, LocalConstantPointerCase as lower_case), static constant casing (StaticConstantCase as UPPER_CASE), and protected member suffix (ProtectedMemberSuffix as '_').
E2E Subsystem
src/e2e/e2e_crc.cpp, src/e2e/e2e_profile_registry.cpp, src/e2e/e2e_protection.cpp
CRC bit-check conditions made explicitly boolean; local variables promoted to const; null-check logic refactored from implicit to explicit nullptr comparisons.
Event Publisher
src/events/event_publisher.cpp
Local temporaries (already_exists, time_since_last, result) qualified with const for improved immutability.
Platform Memory Management
src/platform/freertos/memory.cpp, src/platform/threadx/memory.cpp
Null-check conditions changed to explicit nullptr comparisons; FreeRTOS pool-bounds arithmetic refactored from pointer-difference on char\\* to address-based std::uintptr_t arithmetic.
Message & Transport
src/someip/message.cpp, src/transport/endpoint.cpp
Copy constructors converted from explicit member-wise initialization to compiler-generated defaults; validation logic refined with const qualifiers and explicit character-check style (std::isdigit(...) == 0, std::isxdigit(...) == 0).
TP Subsystem
src/tp/tp_manager.cpp, src/tp/tp_reassembler.cpp, src/tp/tp_segmenter.cpp
Local variables marked const; range-based loop introduced in reassembler; null-check refactored to explicit comparison.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 Const whispers through the code so clean,
Where pointers now say what they mean,
Copy constructors take their rest,
While defaults do the job the best!
Style rules aligned from tip to toe—
Watch the codebase gently grow!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.27% 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 'fix: remediate batch 3 clang-tidy violations' accurately describes the main objective of the pull request, which is to address the third batch of clang-tidy violations across multiple files through configuration updates, const-correctness improvements, and code modernization.

✏️ 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-batch3

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: 3

🤖 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/tp/tp_reassembler.cpp`:
- Around line 52-53: The computation of tp_header uses left shifts on uint8_t
values which are promoted to int and can overflow in C++17; update the
expression that defines tp_header so each byte operand
(payload[16]..payload[19]) is cast to uint32_t (e.g.
static_cast<uint32_t>(payload[i])) before shifting and combine with | to form
the uint32_t tp_header in the tp_reassembler.cpp file.

In `@src/tp/tp_segmenter.cpp`:
- Around line 105-106: The subtraction of a fixed overhead from
config_.max_segment_size (used when computing first_payload_size and the similar
calculation at lines ~145-146) can underflow because size_t is unsigned; change
the logic to compute an effective_capacity by checking if
config_.max_segment_size > overhead (16 + 4) and using config_.max_segment_size
- overhead, otherwise 0, then set first_payload_size =
std::min(effective_capacity, static_cast<size_t>(total_length)); apply the same
guarded pattern to the other payload-size calculation so no unsigned underflow
can occur.
- Line 87: The sequence counter next_sequence_number_ is being advanced twice:
once by using post-increment when assigning uint8_t const sequence_number =
next_sequence_number_++; and again at the function end, which skips sequence
values; fix by not incrementing twice — either stop incrementing at the end
(remove the extra increment) or stop incrementing at assignment (change the
assignment to use the current value: use next_sequence_number_ without ++ and
let the single increment at the function end remain); update references to
sequence_number and next_sequence_number_ accordingly so only one increment
occurs per message.
🪄 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: 6700c7a6-45b8-4a6a-8bbb-38e5f4a02209

📥 Commits

Reviewing files that changed from the base of the PR and between 5f3c258 and 3f36945.

📒 Files selected for processing (12)
  • .clang-tidy
  • src/e2e/e2e_crc.cpp
  • src/e2e/e2e_profile_registry.cpp
  • src/e2e/e2e_protection.cpp
  • src/events/event_publisher.cpp
  • src/platform/freertos/memory.cpp
  • src/platform/threadx/memory.cpp
  • src/someip/message.cpp
  • src/tp/tp_manager.cpp
  • src/tp/tp_reassembler.cpp
  • src/tp/tp_segmenter.cpp
  • src/transport/endpoint.cpp

Comment thread src/tp/tp_reassembler.cpp Outdated
Comment thread src/tp/tp_segmenter.cpp Outdated
Comment thread src/tp/tp_segmenter.cpp Outdated
- Cast uint8_t to uint32_t before left-shifting in TP header parsing
  to avoid signed integer overflow from int promotion
- Fix double-increment of sequence number in create_multi_segments
  (post-increment at assignment + modular increment at end skipped
  one sequence value per call)
- Guard unsigned subtraction in segment payload-size calculations
  to prevent underflow when max_segment_size < overhead

Made-with: Cursor
@vtz vtz merged commit a216ab0 into main Apr 13, 2026
43 checks passed
@vtz vtz deleted the feat/clang-tidy-batch3 branch April 13, 2026 17:55
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