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
bug(stl): fl::aligned_alloc ignores alignment on ARM/AVR/ESP8266 (returns plain malloc) #4817
Found while doing #4792 (part of #4801); flagged by CodeRabbit on #4816.
fl::aligned_alloc(alignment, size) (src/fl/stl/cstdlib.cpp.hpp:22) ignores alignment on FL_IS_AVR, FL_IS_ESP8266, FL_IS_ARM, FL_IS_APOLLO3 and FL_IS_CI13XX, and returns plain malloc (8-byte aligned on ARM). That avoids newlib's posix_memalign link error, but it means any caller that needs more than malloc's alignment silently gets less. Examples are DMA/cache-line buffers and over-aligned types. On Teensy 4 / Cortex-M7, arm_dcache_delete on an under-aligned buffer can discard neighbouring heap data.
Proposed fix
On these targets, over-allocate by alignment - 1 + sizeof(void*), align the returned pointer, and stash the original pointer immediately before it. fl::aligned_free then reads it back. This needs no posix_memalign.
Acceptance
Unit test: aligned_alloc(32/64, n) returns aligned pointers and aligned_free releases them (host plus an ARM board build).
Audit existing callers that relied on the old behavior.
Activity
fix(stl): reject size overflow in aligned_alloc_via_malloc (#4817 rev…
fix(stl): honour alignment in fl::aligned_alloc on bare-metal; restor…