https://bugs.kde.org/show_bug.cgi?id=474332
Bug ID: 474332 Summary: aligned_alloc under Valgrind returns nullptr when alignment < sizeof(void *) Classification: Developer tools Product: valgrind Version: unspecified Platform: Archlinux OS: Linux Status: REPORTED Severity: normal Priority: NOR Component: memcheck Assignee: jsew...@acm.org Reporter: smj...@gmail.com Target Milestone: --- STEPS TO REPRODUCE 1. Compile and run the following C snippet: #include <stdlib.h> #include <stdio.h> int main() { char *p = aligned_alloc(4, 4); if(p == NULL) { printf("Allocation failed!\n"); return 1; } printf("Allocation succeeded!\n"); return 0; } 2. Then run it again under Valgrind OBSERVED RESULT When running on its own the allocation succeeds, when running under Valgrind it fails EXPECTED RESULT Both cases succeed. ADDITIONAL INFORMATION Looking at the source code the problem seems to be highlighted in the comment here (and then the subsequent check); https://sourceware.org/git/?p=valgrind.git;a=blob;f=coregrind/m_replacemalloc/vg_replace_malloc.c;hb=23250889de4e2079ad1ede6874cc824bc9dd92db#l2179 Valgrind expects the alignment to be a multiple of sizeof(void *), but this is not true in glibc https://sourceware.org/git/?p=glibc.git;a=blob;f=malloc/malloc.c;hb=a43003ebf674f7af8c4b8d6d1b682244f1a28719#l3548, which only checks that it's a power of two (and then internally adjusts if it's smaller than some constant, but it doesn't make it fail). That limit seems to be for posix_memalign, but as far as I know the C standard says that a valid alignment is implementation dependent, and I would expect for Valgrind on Linux to be the same as for glibc. -- You are receiving this mail because: You are watching all bug changes.