Repository navigation
Conversation
malloc(), calloc() and realloc() must return memory that is aligned for every type (C11 7.22.3), that is to alignof(max_align_t). Add mm test case 9: it allocates, frees and reallocates blocks of many sizes and checks each pointer. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
xiaoxiang781216
approved these changes
Nov 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
depends-on: apache/nuttx/pull/21961
Summary
malloc(),calloc()andrealloc()must return memory that is aligned for every type (C11 7.22.3), that is toalignof(max_align_t). No test checks this today. This PR adds case 9 to the mm cmocka suite (cmocka_mm_test,CONFIG_CM_MM_TEST): it allocates 1024 blocks of many sizes, frees one in three, reallocates the others and fills the holes withcalloc(), and counts the pointers that are not aligned toalignof(max_align_t). The case gets the alignment fromoffsetof()of amax_align_tmember, so it needs no C11 keyword. It reads each address back through avolatile: GCC assumes thatmalloc()memory is aligned to 16 on 64-bit targets, and at -O2 it removes a check such as(uintptr_t)p % 16.Depends on apache/nuttx#21961, which makes the default heap alignment 16 on 64-bit architectures. With the old default 8, this case fails there.
Impact
Test only. The new file is in the existing
kernel/mm/cases/directory, which the Make and CMake builds take with a wildcard.Testing
cmocka_mm_testwithCONFIG_CM_MM_TEST(and cmocka:ALLOW_MIT_COMPONENTS,LIBC_REGEX,ARCH_SETJMP_H):test_nuttx_mm09FAIL: 1023 pointers not aligned; cases 1-8 PASStest_nuttx_mm09FAIL: 997 pointers not aligned; cases 1-8 PASSostest passes (exit status 0) in the same qemu-armv8a:nsh images. tools/checkpatch.sh passes.