summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/sanitizer_common/sanitizer_allocator_checks.h
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
commitdcf0097962e4506aec59fbbd01c874527d2e061d (patch)
tree1a41b71908299f93693d176a5cb9b94ea7a9de77 /compiler-rt/lib/sanitizer_common/sanitizer_allocator_checks.h
parent9e5eafbaa8ab0d49ccfd197a91b386e9aba28972 (diff)
downloadbcm5719-llvm-dcf0097962e4506aec59fbbd01c874527d2e061d.tar.gz
bcm5719-llvm-dcf0097962e4506aec59fbbd01c874527d2e061d.zip
[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 llvm-svn: 334316
Diffstat (limited to 'compiler-rt/lib/sanitizer_common/sanitizer_allocator_checks.h')
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_allocator_checks.h8
1 files changed, 5 insertions, 3 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_checks.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_checks.h
index b61a8b2eb3b..61bd26e68cc 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_checks.h
+++ b/compiler-rt/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.
OpenPOWER on IntegriCloud