summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common
diff options
context:
space:
mode:
authorAlex Shlyapnikov <alekseys@google.com>2018-06-08 20:40:35 +0000
committerAlex Shlyapnikov <alekseys@google.com>2018-06-08 20:40:35 +0000
commit77b27c99d38c3a0905272ea8a2b133b6c77b300c (patch)
tree4d95f18732d07c339f33b6c0074621442cd44478 /lib/sanitizer_common
parent8c252bbd0b5829284775ce609670a8f3de464a2c (diff)
[Sanitizers] Check alignment != 0 for aligned_alloc and posix_memalign
Summary: Move the corresponding tests to the common folder (as all of the sanitizer allocators will support this feature soon) and add the checks specific to aligned_alloc to ASan and LSan allocators. Reviewers: vitalybuka Subscribers: srhines, kubamracek, delcypher, #sanitizers, llvm-commits Differential Revision: https://reviews.llvm.org/D47924 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@334316 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common')
-rw-r--r--lib/sanitizer_common/sanitizer_allocator_checks.h8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/sanitizer_common/sanitizer_allocator_checks.h b/lib/sanitizer_common/sanitizer_allocator_checks.h
index b61a8b2eb..61bd26e68 100644
--- a/lib/sanitizer_common/sanitizer_allocator_checks.h
+++ b/lib/sanitizer_common/sanitizer_allocator_checks.h
@@ -44,16 +44,18 @@ INLINE void *SetErrnoOnNull(void *ptr) {
// of alignment.
INLINE bool CheckAlignedAllocAlignmentAndSize(uptr alignment, uptr size) {
#if SANITIZER_POSIX
- return IsPowerOfTwo(alignment) && (size & (alignment - 1)) == 0;
+ return alignment != 0 && IsPowerOfTwo(alignment) &&
+ (size & (alignment - 1)) == 0;
#else
- return size % alignment == 0;
+ return alignment != 0 && size % alignment == 0;
#endif
}
// Checks posix_memalign() parameters, verifies that alignment is a power of two
// and a multiple of sizeof(void *).
INLINE bool CheckPosixMemalignAlignment(uptr alignment) {
- return IsPowerOfTwo(alignment) && (alignment % sizeof(void *)) == 0; // NOLINT
+ return alignment != 0 && IsPowerOfTwo(alignment) &&
+ (alignment % sizeof(void *)) == 0; // NOLINT
}
// Returns true if calloc(size, n) call overflows on size*n calculation.