Repository navigation
Align the PixelUtil stub's setRangeRGB with the fixed implementation - #8
Conversation
The native suite's PixelUtil stub had a *different* setRangeRGB from the real one in ArduinoLibs: it treated length == 0 as start..num-1 where the implementation means the whole strip (0..num-1). That is exactly how the out-of-bounds range bug in the real setRangeRGB survived — the only test that looked like coverage of it exercised a hand-written mock that happened to be safe where the real one was not. The stub now has the same three-branch shape as the fixed implementation (aphelps/ArduinoLibs pixelutil-setrange-oob): length == 0 fills the whole strip regardless of start, start >= numPixels() draws nothing, and an over-long range clamps to the end. The "setRangeRGB [start+length]" debug line is unchanged so existing assertions still pass. Two new cases pin the semantics so the stub cannot silently drift back: zero length with a non-zero start fills 0..num-1, and start >= numPixels() (both == and far past) writes nothing. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015KSu1SeP42JExkGvrWGd2u
Four minor review findings applied directly:
- Stub's length == 0 branch now delegates to setAllRGB() like the real
PixelUtil::setRangeRGB, keeping the stub in lockstep with the real
call chain (and emitting the same setAllRGB debug line).
- Stub's start >= numPixels() guard now mirrors the real
implementation's DEBUG1_VALUELN("setRangeRGB: start past end:", ...)
diagnostic so tests can observe that the guard branch actually ran.
- New test pins the clamp branch: {5,10} on an 8-pixel strip writes
pixels 5..7 only, with no wrap onto the strip front.
- Split the two-scenario start-past-end test into start_at_end and
start_far_past_end so a boundary regression can't mask the far-past
result; both now also assert the guard's debug line.
Native suite: 58/58 (was 56/56).
Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015KSu1SeP42JExkGvrWGd2u
aphelps-reviewer-bot
left a comment
There was a problem hiding this comment.
Reviewed the diff at e0ea310 (stub alignment + 4 new setRangeRGB tests). No findings — the diff is clean.
Verified during review:
- The stub's
setRangeRGBnow mirrors the real fixedPixelUtil::setRangeRGB(ArduinoLibs 73d9e1d) branch-for-branch:length == 0→ whole strip,start >= num→ no-op with the sameDEBUG1_VALUELNguard diagnostic, over-long range clamps via the sameavail/lenmath. - The guard diagnostic assertion is sound: the native build sets
-DDEBUG_LEVEL=5(platformio.ini:28) soDEBUG1_VALUELNis active, and the stub's_debug_value_emitformatskey << +valwith no separator, matching the asserted"setRangeRGB: start past end:8"/":200"strings exactly. - The trailing
setRangeRGB [start+length]log line is preserved on all branches, so the pre-existing log assertions keep passing. - The new tests cover the plan's required stub cases: zero-length-with-nonzero-start fills 0..num-1 (the exact divergence the old stub had), start == num and start far past end write nothing (with the guard line asserted so a skipped call can't fake a pass), and over-long clamps with an explicit no-wrap-to-front check.
- No AVR portability concern: the stub is compiled only in the native host env (the simavr track builds HMTL_Module firmware, not the stubs), and stub Debug.h already used
<sstream>before this change. - Ran the full native suite at the tip: 58/58 test cases pass, including all 4 new ones.
aphelps-claude-bot
left a comment
There was a problem hiding this comment.
⏳ Testing Tasks — human confirmation required before merge
Thanks for the approval. Holding the merge on one unchecked ## Testing Required item, and I want to be straight that it may well be a no-op — but ticking it is a hardware judgement, not mine to make.
The item: "Bench check only if the unchecked-setter policy changes."
Why it looks inapplicable. The recorded decision (plan Notes, 2026-08-05) was that the three setPixelRGB(uint16_t led, …) overloads stay unchecked and fast — only getColor() and setDistinct() gained bounds checks. So the item's own precondition is not met.
The one real behaviour change it flags, independent of that condition: for start == numPixels() exactly, the old code was not undefined — it clamped and flooded the whole strip. The fix makes it a no-op. A sender that had been using an out-of-range start as an accidental "all pixels" command would go dark. That case is asserted in the host suite, but only you know whether anything on the bus was relying on it.
If nothing was, /ack-tested on this PR and the bot merges the stack.
Everything else is verified at the approved heads (ArduinoLibs 73d9e1d, HMTL e0ea310):
make -C ArduinoLibs/test
rs485_receive_test 55 checks, 0 failures
pixelutil_test PIXEL_ADDR_TYPE 1 byte PASS: 51 checks, 0 failures
pixelutil_test_big PIXEL_ADDR_TYPE 2 bytes PASS: 55 checks, 0 failures
make test STRICT=1 OK — all submodule host tests passed
HMTL pio test -e native 58 test cases: 58 succeeded (incl. test_pixelutil)
pio run -e ampworks SUCCESS, 49.30s (formality — PixelUtil is not on the WLED build path)
Negative control, reverting setRangeRGB to the pre-fix implementation in a scratch worktree:
pixelutil_test FAIL: 51 checks, 14 failures
pixelutil_test_big FAIL: 55 checks, 16 failures
Red by the sentinel check under both widths — every failure is a sentinels intact assertion, exit=1, no segfault. That distinction was the point: a crash would have meant an undersized guard pad and would not have counted as proof.
aphelps/ArduinoLibs#13 stops setRangeRGB writing out of bounds when range.start exceeds numPixels(), and aphelps/HMTL#8 aligns HMTL_Test's stub with the fixed semantics so the native suite stops encoding the old behaviour as the expectation. Both pointers move in one commit deliberately: the plan's post-merge checks run from here and reach the new ArduinoLibs suite only through these pointers, so a split bump would leave a window where the super-repo verifies one half against the other's old code. Nothing on the WLED firmware build path changes — PixelUtil is not reached from the ampworks env, which is why there is no WLED submodule PR in this stack. Verified on this combination before opening: make -C ArduinoLibs/test — 51 checks (uint8_t) + 55 checks (BIG_PIXELS), 0 failures make test STRICT=1 — all submodule host tests, sweep across four ABIs x both pixel widths, 460/460 perturbations red as required Claude-Session: https://claude.ai/code/session_013HqzdRdTRnreSvevaQGQSJ Co-authored-by: aphelps-claude-bot <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
What / why
Companion to aphelps/ArduinoLibs#13 (the setRangeRGB out-of-bounds fix). Conceptually depends on that PR — the stub now mirrors its fixed implementation — but is mergeable independently: this only changes the native-suite stub and its tests, not firmware.
The native suite's
stubs/PixelUtil.hhad a differentsetRangeRGBfrom the real one: it treatedlength == 0asstart..num-1where the implementation means the whole strip (0..num-1), and it clamped safely where the real one wrapped and walked off the array. That divergence is exactly how the real bug survived —test_pixelutil.cppread as coverage ofPixelUtil::setRangeRGBand was coverage of a hand-written mock that happened to be correct where the real one is not. For reference, the real defect this stub was masking (10-pixel strip,start = 200):uint8_t)leds[200..265]-DBIG_PIXELS(uint16_t)leds[200..65545]Changes
stubs/PixelUtil.h:setRangeRGBnow has the same three-branch shape as the fixed implementation —length == 0fills the whole strip regardless ofstart,start >= numPixels()draws nothing, an over-long range clamps to the end. ThesetRangeRGB [start+length]debug line is unchanged, so existing log assertions still pass. Nostd::headers added (the stub is also meant to build under avr-g++).test/test_pixelutil/test_pixelutil.cpp: two new cases so the stub cannot silently drift back — zero length with a non-zero start fills0..num-1, andstart >= numPixels()(both== numand far past) writes nothing.Behaviour-change callout (inherited from the ArduinoLibs fix)
start == numPixels()exactly used to reach "fill the whole strip" in the real implementation via the accidental clamp-to-0 path; it is now a no-op, and the stub + new test assert that. A sender relying on an out-of-rangestartas "all pixels" goes dark.Test results
make test-native:Note: the plan mentions
tests/layout/Makefilecompiling this stub under avr-g++; that Makefile does not exist onmain(only an untracked coverage note intests/layout/), so there was nothing to run there — the stub change adds no new headers regardless.🤖 Generated with Claude Code
https://claude.ai/code/session_015KSu1SeP42JExkGvrWGd2u