Repository navigation
Description
Motivation
FastLED already controls every allocation site in its own code via cpp linting (bare_allocation_checker.py -- bans raw new/malloc/delete/free in src/, requires fl::unique_ptr / fl::shared_ptr). This means we have a chokepoint we can instrument: a FastLED-owned allocator wrapper that checks every allocation for null and emits a diagnostic before the caller dereferences the null pointer.
The same OOM problem on the Arduino-core side is filed as zackees/ArduinoCore-LPC8xx#30 (HardFault override) -- that fix catches most OOM crashes once they cascade into null-deref → HardFault. But it has two limitations:
- Silent miss case: if the first access via the null pointer is a small-offset read/write that lands in flash (vector table region), the access is silently ignored on M0+ and the program continues with garbage state. No HardFault fires, no emit, eventually crashes downstream with a confusing PC.
- Worse PC info when it DOES fault: the captured PC points at the use site, not the allocation site. Decoding which
newcall returned null requires objdumping the firmware.
A FastLED-side OOM trap catches both: every allocation is checked at the point of allocation, the size is logged, the diagnostic is emitted before any null pointer is propagated to a caller.
Priority
LOW. The LPC8xx-side HardFault override (#30 on that repo) covers the bulk of the diagnostic gap. The remaining ~20% of OOM cases that slip through (silent flash-region writes) are rare in C++ object access patterns -- virtual calls, multi-byte field accesses, and array iteration all eventually walk into unmapped memory and trigger HardFault. The FastLED-side trap is a refinement that turns "FAULT: HardFault PC=0x..." into "FAULT: OOM size=0x40 at allocator.cpp.hpp:153", which is faster to triage but not the primary fix.
This issue exists so the leverage is documented and a future contributor can pick it up; we are not blocking #3300 / #3102 on it.
Proposed design
Single chokepoint
src/fl/stl/allocator.cpp.hpp already centralizes FastLED's allocation primitive (fl::Malloc -- the one function that the bare_allocation_checker linter steers every site toward). Add a null-check + emit:
void* Malloc(size_t bytes) FL_NO_EXCEPT {
void* p = (DefaultAlloc(bytes));
if (!p) {
fl::diagnostics::emit_oom(bytes); // see "platform emit hook" below
}
return p;
}Platform emit hook (fl::diagnostics::emit_oom)
Lives in src/fl/diagnostics/oom.h + oom.cpp.hpp. Per-platform:
| Platform | Emit path | Reboot |
|---|---|---|
| LPC8xx (M0+) | direct USART0 TXDAT sync write (mirrors the Arduino-core HardFault emit's helper if #30 lands) | AIRCR.SYSRESETREQ |
| STM32 (M0/M3/M4/M7) | direct USART1 / lowest-numbered enabled USART | AIRCR.SYSRESETREQ |
| RP2040 | UART0 register write | AIRCR.SYSRESETREQ |
| AVR / ATmega | direct UDR0 register write | wdt_enable(WDTO_15MS); while(1){} |
| ESP32 / Teensy 4 / host | fprintf(stderr, ...) + abort() (FPU + plentiful RAM; OOM is recoverable, this is debug-build only) |
-- |
The "no allocation, no printf, no Serial.print" rule applies to the embedded paths. The hook signature:
namespace fl { namespace diagnostics {
[[noreturn]] void emit_oom(fl::size bytes) FL_NO_EXCEPT;
}}Per-platform format
FAULT: OOM size=0x<hex> at <PC of caller> -- the PC is captured via __builtin_return_address(0) so the emit identifies the failing allocation site. Decode via arm-none-eabi-addr2line firmware.elf 0x<pc> to get file:line.
Gating
- Default ON for low-memory platforms (
!FL_PLATFORM_HAS_LARGE_MEMORY). - Default OFF for large-memory platforms (FPU + 256 KB+ RAM; OOM there is a programming error, not a hardware reality, and the emit cost isn't justified).
- User opt-out via
FASTLED_NO_OOM_TRAPfor production builds that prefer the bare-pointer-fast-path.
Acceptance criteria
-
fl::Mallocinsrc/fl/stl/allocator.cpp.hppchecks for null and callsfl::diagnostics::emit_oom(bytes)on failure. -
fl::diagnostics::emit_oomimplemented for LPC8xx, STM32, RP2040, AVR, host -- each in its own<platform>/oom.impl.hppshim. - Caller-PC included in the emit via
__builtin_return_address(0). -
FASTLED_NO_OOM_TRAPopt-out gate. - Default-on for
!FL_PLATFORM_HAS_LARGE_MEMORY, default-off otherwise. - Flash budget per platform: <= ~250 B (the emit helpers are mostly shared with the per-platform fault-emit path that latest release will not install in ardduino w/o manual edits #30 establishes for LPC).
Cross-references
- Blocking dependency: none. Can land independently of the Arduino-core fix (latest release will not install in ardduino w/o manual edits #30 on
zackees/ArduinoCore-LPC8xx); the two are complementary, not sequential. - Related: HardFault_Handler silently spins forever — emit useful diagnostic + reboot instead framework-arduino-lpc8xx#30 -- HardFault override. Catches OOM via null-deref cascade with worse diagnostic info. This issue catches OOM at the allocation site with better info.
- Bring-up motivator: [BLOCKER] LPC845-BRK AutoResearch bring-up echo returns empty RX (suspected HardFault) — blocks #3102 #3300 -- the LPC845-BRK bring-up echo silence that exposed the silent-crash surface.
- Test companion: FastLED/FastLED#TBD (filed alongside this issue) -- intentional OOM / stack-blow test that validates the device emits the proper error output.
Out of scope
- Replacing every existing call site's
fl::Mallocwith the new checking version -- they already go throughfl::Mallocper thebare_allocation_checkerlinter. No call-site changes needed. - Adding a per-instantiation memory-resource override (we already have
fl::memory_resource). The OOM trap fires at the default resource'sdo_allocate; custom resources can opt in by routing throughfl::Mallocor skip the trap entirely. - Recovering from OOM (caller-side fallback). This is hardware-side detection only; recovery is the application's choice.
Refs
src/fl/stl/allocator.cpp.hpp-- the chokepoint.src/fl/stl/malloc.cpp.hpp-- the platform malloc wrapper.ci/lint_cpp/bare_allocation_checker.py-- the lint rule that steers all allocations tofl::Malloc.agents/docs/cpp-standards.md-- the project's "no bare new/delete" rule.
Filed during /clud-fix burn-down on #3208 while diagnosing the #3102 / #3300 bring-up echo silence.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
zackees commentedon Jun 23, 2026
Tracking this under the new LPC845-BRK / LPC8xx AutoResearch coordination meta: #3348.
Keeping this issue open for now as optional LPC8xx validation safety-net work. If diagnostics are deferred, close this separately with rationale from #3348 rather than folding it silently into the meta.
zackees commentedon Jul 6, 2026
Closing as not planned. We are not pursuing the standalone in-FastLED allocator OOM wrapper path.
Active LPC board tracking is consolidated under #3348, with only #3300 and #3302 remaining as sub-issues.