fix: remediate batch 4 clang-tidy violations#229
Conversation
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
📝 WalkthroughWalkthroughThis PR modernizes C++ code practices across the codebase by adding Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (16)
include/events/event_types.hinclude/sd/sd_message.hinclude/sd/sd_types.hsrc/common/result.cppsrc/e2e/e2e_profiles/standard_profile.cppsrc/platform/freertos/memory.cppsrc/platform/threadx/memory.cppsrc/rpc/rpc_server.cppsrc/sd/sd_client.cppsrc/sd/sd_message.cppsrc/sd/sd_server.cppsrc/serialization/serializer.cppsrc/someip/types.cppsrc/tp/tp_segmenter.cppsrc/transport/tcp_transport.cppsrc/transport/udp_transport.cpp
- 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
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: Addexplicitto single-argument constructors insd_types.h,sd_message.h,event_types.hto prevent unintended implicit type conversionsModernize (16 fixes)
modernize-use-auto: Useautowhen initializing with casts to avoid duplicating the type name (9 sites)cppcoreguidelines-avoid-c-arrays: Replace C-style arrays withstd::array(7 sites in memory pools, byte buffers, and IP address strings)Naming (3 fixes)
readability-identifier-naming: Rename static constants toUPPER_CASE(result_strings,type_strings,code_strings)Const-correctness (~50 fixes)
misc-const-correctness: Addconstto local variables that are never modified (sd_client, sd_server, sd_message, rpc_server, serializer, tcp_transport, udp_transport)Test plan
Ref: #222
Made with Cursor
Summary by CodeRabbit
Refactor
Style