[PATCH] D35275: [Sanitizers] ASan/MSan/LSan allocators set errno on failure.

Matt Morehouse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 14 07:52:57 PDT 2017


morehouse added inline comments.


================
Comment at: lib/msan/msan_allocator.cc:287
+  if (UNLIKELY(!IsPowerOfTwo(alignment) ||
+               (alignment % sizeof(void *)) != 0)) {  // NOLINT
+    Allocator::FailureHandler::OnBadRequest();
----------------
vitalybuka wrote:
> morehouse wrote:
> > vitalybuka wrote:
> > > maybe just, pointer should be always power of two?
> > > if (UNLIKELY((alignment % sizeof(void *)))) { 
> > > 
> > > 
> > From the posix_memalign man page:
> > 
> > > The function posix_memalign()  allocates  size  bytes  and  places  the
> > > address  of  the allocated memory in *memptr.  The address of the allo‐
> > > cated memory will be a multiple of alignment, which must be a power  of
> > > two  and  a  multiple  of sizeof(void *).
> > 
> > 
> yes, but  sizeof(void *) is already power of two
Suppose sizeof(void *) is 8 and alignment is 24.  Then alignment % sizeof(void *) == 0 but alignment is not a power of 2.


https://reviews.llvm.org/D35275





More information about the llvm-commits mailing list