You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fl::unordered_map::rehash_internal puts ~1 KB of scratch on the stack; overflows ESP8266's 4 KB loop stack #4926
fl::unordered_map::rehash_internal() (src/fl/stl/unordered_map.h) declares two stack locals:
fl::vector_inlined<Entry, INLINED_COUNT> old, which reserves room for 8 whole Entry values inline.
fl::bitset<1024> old_occupied, which is 128 bytes.
For large values such as fl::Rpc's RpcEntry, that is about 1 KB of temporary stack on each grow.
Impact
ESP8266 runs setup()/loop() on a 4 KB stack. In the AutoResearch low-memory surface, binding the 23rd RPC method grows the registry from 32 to 64 buckets. That overflowed the stack, and the board boot-looped with Stack smashing detected from cont_check.
Evidence
Measured on an ESP8266EX through the resetCause RPC, cont_stack_free:
With 22 binds: 368 bytes free.
With one more bind: boot loop.
After moving the scratch to the heap: 1,568 bytes free with all binds in place.
Fix
Gate on the platform memory tier:
Where FL_PLATFORM_HAS_LARGE_MEMORY is set, keep the scratch on the stack. There is no heap round trip per rehash.
Otherwise (ESP8266, AVR, Teensy LC/3.x, STM32F1, …), allocate the scratch on the heap.
Found during the ESP8266 HSPI APA102 work (#4925).
Activity
fix(stl): gate unordered_map rehash scratch on memory tier (#4926)
fix(stl): allocate small-memory rehash scratch from the map's memory_…
fix(stl): allocate small-memory rehash scratch from the map's memory_…
fix(stl): keep unordered_map rehash scratch off small stacks (FastLED…