Skip to content

fix: remediate batch 4 clang-tidy violations#229

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

fix: remediate batch 4 clang-tidy violations#229
vtz merged 2 commits intomainfrom
feat/clang-tidy-batch4

Conversation

@vtz
Copy link
Copy Markdown
Owner

@vtz vtz commented Apr 13, 2026

Summary

Fourth batch of clang-tidy remediations targeting explicit conversions, modernization, naming conventions, and const-correctness across 16 files.

Changes by category

Explicit conversions (9 constructors)

  • hicpp-explicit-conversions: Add explicit to single-argument constructors in sd_types.h, sd_message.h, event_types.h to prevent unintended implicit type conversions

Modernize (16 fixes)

  • modernize-use-auto: Use auto when initializing with casts to avoid duplicating the type name (9 sites)
  • cppcoreguidelines-avoid-c-arrays: Replace C-style arrays with std::array (7 sites in memory pools, byte buffers, and IP address strings)

Naming (3 fixes)

  • readability-identifier-naming: Rename static constants to UPPER_CASE (result_strings, type_strings, code_strings)

Const-correctness (~50 fixes)

  • misc-const-correctness: Add const to local variables that are never modified (sd_client, sd_server, sd_message, rpc_server, serializer, tcp_transport, udp_transport)

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

    • Updated multiple constructors to prevent unintended implicit conversions
    • Enhanced const-correctness throughout codebase
    • Modernized memory management with safer container types
    • Improved local variable declarations for clarity
  • Style

    • Updated naming conventions for internal static variables

Explicit conversions:
- Add explicit to 9 single-argument constructors in SD, event
  type headers to prevent implicit conversions

Modernize:
- Use auto when initializing with casts (9 sites)
- Replace C-style arrays with std::array (7 sites across
  freertos/memory, threadx/memory, sd_message, tp_segmenter,
  tcp_transport, udp_transport)

Naming:
- Rename static constants to UPPER_CASE (result_strings,
  type_strings, code_strings)

Const-correctness:
- Add const to ~50 local variables that are never modified
  across sd_client, sd_server, sd_message, rpc_server,
  serializer, tcp_transport, udp_transport

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

coderabbitai Bot commented Apr 13, 2026

📝 Walkthrough

Walkthrough

This PR modernizes C++ code practices across the codebase by adding explicit keywords to type constructors, replacing raw C-style arrays with std::array, and applying const-correctness improvements to local variables throughout multiple modules.

Changes

Cohort / File(s) Summary
Constructor Explicitness
include/events/event_types.h, include/sd/sd_message.h, include/sd/sd_types.h
Added explicit keyword to constructors for EventSubscription, EventNotification, SdEntry, ServiceEntry, EventGroupEntry, SdOption, ServiceInstance, EventGroup, and EventGroupSubscription to prevent implicit conversions.
Array Modernization
src/platform/freertos/memory.cpp, src/platform/threadx/memory.cpp, src/tp/tp_segmenter.cpp, src/transport/tcp_transport.cpp, src/transport/udp_transport.cpp
Replaced raw C-style arrays with std::array for static pool buffers, serialization headers, and socket receive buffers; updated pointer access patterns to use .data().
Const-Correctness Enhancements
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/transport/tcp_transport.cpp
Added const qualifiers to local variables, iterators, and temporaries throughout to strengthen immutability guarantees and prevent unintended mutations.
Static Map Naming
src/common/result.cpp, src/someip/types.cpp
Renamed static lookup maps from result_strings/type_strings/code_strings to uppercase convention (RESULT_STRINGS/TYPE_STRINGS/CODE_STRINGS); updated iterator constness in lookup operations.
Type Deduction and Minor Adjustments
src/e2e/e2e_profiles/standard_profile.cpp
Changed explicit type declarations to auto deduction for freshness computation variables; added explicit cast to uint32_t in serialization length computation in src/sd/sd_message.cpp.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 Explicit paths now pave the way,
No silent conversions led astray!
Arrays dressed in std:: attire,
Constants standing guard, climbing higher.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 63.77% 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
Title check ✅ Passed The title accurately summarizes the main objective of the changeset: applying clang-tidy remediations across multiple files to improve code quality through explicit conversions, modernization, naming conventions, and const-correctness.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/clang-tidy-batch4

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/sd/sd_message.cpp`:
- Around line 547-549: In sd_message.cpp where you read const uint16_t
option_len = (data[offset] << 8) | data[offset + 1] and then do offset += 4 +
option_len, add an explicit boundary check against the options block end
(compute remaining_options = options_end - offset or remaining_bytes from the
containing options length) before advancing; if (4 + option_len) >
remaining_options, handle as malformed (return error/abort parsing) instead of
advancing offset, to prevent skipping past the declared options boundary and
potential buffer overruns.
- Around line 482-483: The bitwise assembly of 32-bit values from bytes (e.g.
the expression that computes entries_length using (data[offset] << 24) |
(data[offset+1] << 16) | ...) invokes integer promotion to signed int and can
cause UB for bytes ≥ 128; fix by casting each byte to uint32_t before shifting
(e.g. static_cast<uint32_t>(data[offset]) << 24, etc.) and apply the same change
to every similar expression in this file (all places that build a uint32_t from
data[...] bytes).
🪄 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: cc35feb3-d6b9-486a-a842-d53eb2aff007

📥 Commits

Reviewing files that changed from the base of the PR and between a216ab0 and 8f4ea39.

📒 Files selected for processing (16)
  • include/events/event_types.h
  • include/sd/sd_message.h
  • include/sd/sd_types.h
  • src/common/result.cpp
  • src/e2e/e2e_profiles/standard_profile.cpp
  • src/platform/freertos/memory.cpp
  • src/platform/threadx/memory.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/someip/types.cpp
  • src/tp/tp_segmenter.cpp
  • src/transport/tcp_transport.cpp
  • src/transport/udp_transport.cpp

Comment thread src/sd/sd_message.cpp Outdated
Comment thread src/sd/sd_message.cpp Outdated
- Cast uint8_t to uint32_t before left-shifting in all byte-assembly
  patterns to prevent signed integer overflow from int promotion
  (17 sites across entry, option, and message deserialization)
- Add boundary check for unknown option skip length against the
  declared options block end to prevent buffer overruns

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