FreeRTOS-Kernel/portable/MemMang
AniruddhaKanhere 3d4227479d heap_1: reject configTOTAL_HEAP_SIZE <= portBYTE_ALIGNMENT at compile time
Defect: pvPortMalloc() in heap_1.c can return a pointer outside the ucHeap
array when configTOTAL_HEAP_SIZE is configured smaller than or equal to
portBYTE_ALIGNMENT.

Root cause: configADJUSTED_HEAP_SIZE is defined as
( configTOTAL_HEAP_SIZE - portBYTE_ALIGNMENT ). When configTOTAL_HEAP_SIZE is
not larger than portBYTE_ALIGNMENT this unsigned subtraction underflows to a
very large size_t value. The "enough room left" check in pvPortMalloc()
compares an unsigned index against configADJUSTED_HEAP_SIZE, so the underflowed
value defeats the check and an allocation can be handed out past the end of the
heap array.

Fix: add a compile-time (compiler, not preprocessor) size check so a
nonsensical, too-small heap is rejected during the build. The compiler-level
check still works when configTOTAL_HEAP_SIZE is defined with a cast such as
( ( size_t ) 0x2000 ).

A host regression test kept outside this repository demonstrates the fault
before the change and its absence afterwards (red then green).
2026-07-13 14:24:57 -07:00
..
heap_1.c heap_1: reject configTOTAL_HEAP_SIZE <= portBYTE_ALIGNMENT at compile time 2026-07-13 14:24:57 -07:00
heap_2.c fix typo gab -> gap and adjust indentation level (#1097) 2024-06-29 11:37:15 +05:30
heap_3.c Use Regex for Copyright Year in Header Check (#1002) 2024-02-26 09:26:42 -08:00
heap_4.c Change the macro from portMAX_DELAY to SIZE_MAX in order to initialize size_t-type variable correctly (#1310) 2025-08-15 12:37:23 +05:30
heap_5.c Fix spurious heap_5 assert when allocation search reaches end marker (#1425) 2026-06-12 18:55:13 +00:00
ReadMe.url Normalize line endings and whitespace in source files 2022-11-29 15:38:47 -08:00

[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,2
[InternetShortcut]
URL=https://www.FreeRTOS.org/a00111.html
IDList=