Repository navigation
fix(third_party/object_fled): cast size to int in drawSquare bounds checks (#2726) - #2737
Conversation
… checks (#2726) `-Wtype-limits` "comparison of unsigned expression in >= 0 is always true" fires on every Teensy 4.x build (teensy40, teensy41, teensy_octoWS2811) at OjectFLED.cpp.hpp:676 and :690. `size` is uint32_t, so `yCorner + size` (and `xCorner + size`) promotes to unsigned via the usual arithmetic conversions, and the `>= 0` clause becomes always true. This is not just noise — it silently breaks the bounds check whenever `yCorner` is negative: instead of the check failing (and the draw being skipped), `yCorner + size` wraps to a huge unsigned value that still satisfies `>= 0`, and then `< planeY` filters it out. Net effect: today the negative-corner case happens to be safe because of the second clause, but the first clause was meant as the primary "negative-Y" guard. Fix: cast `size` to int in both bounds expressions so the arithmetic stays signed. Matches the convention already used in the for-loop bound (`x <= xCorner + (int)size`) on the same function. This is vendored upstream code (third_party/object_fled/), so the fix should also be PR'd to the upstream `ObjectFLED` repo and pulled back on the next sync. Closes #2726. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR fixes a latent logic bug in the vendored OjectFLED driver's drawSquare function. The end-bound comparisons previously allowed unsigned promotion when corner offsets were negative; the fix casts ChangesSigned/unsigned bounds checking fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/third_party/object_fled/src/OjectFLED.cpp.hpp`:
- Line 682: The array index uses yCorner + size which promotes yCorner to
unsigned and can wrap; change the index math to use a signed cast for size so
the expression is evaluated as signed (e.g., use (yCorner + (int)size) in the
pointer arithmetic), updating the write to leds so ((yCorner + (int)size) *
planeX + x) is used; apply the same signed cast pattern wherever yCorner/size
are combined in the pixel writes (the expressions involving leds, yCorner, size,
planeX, x, and color).
- Line 697: The array index expression causes unsigned promotion when xCorner is
negative; update the indexing in the assignment that writes RGB bytes (the line
setting *((uint8_t*)leds + (xCorner + size + y * planeX) * 3) = ((color >> 16) &
0xFF);) to cast size to signed int (e.g. use (xCorner + (int)size + y * planeX)
* 3) so the bounds check that casts size to int on line 696 matches the indexing
and prevents wraparound.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7896a35a-35ed-44ce-b31d-332336c3221c
📒 Files selected for processing (1)
src/third_party/object_fled/src/OjectFLED.cpp.hpp
…ng (#2726) The previous commit fixed the bounds-check expressions on lines 681/696 but left the corresponding index expressions on lines 682-684 / 697-699 using bare `size` (uint32_t). When `yCorner`/`xCorner` is negative, `yCorner + size` still promotes to unsigned and wraps, writing out of bounds even though the guard passes. Cast `size` to `int` in the indices to match the guard expressions, addressing CodeRabbit review feedback on PR #2737. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Closes #2726.
Summary
-Wtype-limits"comparison of unsigned expression in >= 0 is always true" fires on every Teensy 4.x build (teensy40, teensy41, teensy_octoWS2811) atOjectFLED.cpp.hpp:676and:690.sizeisuint32_t, soyCorner + sizepromotes to unsigned via the usual arithmetic conversions and the>= 0clause becomes always true.This is not just noise — it silently breaks the bounds check whenever
yCorneris negative. Instead of the first clause failing (and the draw being skipped),yCorner + sizewraps to a huge unsigned value that still satisfies>= 0, and the second clause< planeYends up doing all the work. Today the negative-corner case happens to be safe because the second clause filters it out, but the first clause was clearly meant as the primary "negative-Y" guard.Fix
Cast
sizetointin both bounds expressions so the arithmetic stays signed:Matches the convention already used in the same function's for-loop bound (
x <= xCorner + (int)size).Upstream
This is vendored code under
third_party/object_fled/; the same fix should be PR'd to the upstreamObjectFLEDrepo and pulled back on the next sync.Test plan
bash lintclean🤖 Generated with Claude Code
Summary by CodeRabbit