<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - ASan: posix_memalign returns invalid value when allocation fails (macOS)"
href="https://bugs.llvm.org/show_bug.cgi?id=36510">36510</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>ASan: posix_memalign returns invalid value when allocation fails (macOS)
</td>
</tr>
<tr>
<th>Product</th>
<td>compiler-rt
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>MacOS X
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>compiler-rt
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>jbc.engelen@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Reproducing testcase:
```cpp
#include <iostream>
#include <stdlib.h>
int main()
{
void* result;
int code = posix_memalign(&result, 1, ~size_t(0));
std::cout << code << std::endl;
}
```
The output on macOS with XCode 9:
❯ clang++ memalign.cpp -o memaligncpp
❯ ./memaligncpp
22
But with ASan:
❯ clang++ memalign.cpp -fsanitize=address -o memaligncpp
❯ ASAN_OPTIONS=allocator_may_return_null=1 ./memaligncpp
-1
"-1" is an invalid return value.
This is related to <a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED FIXED - posix_memalign should return ENOMEM when allocation fails under allocator_may_return_null=1"
href="show_bug.cgi?id=32968">https://bugs.llvm.org/show_bug.cgi?id=32968</a> which appears to
have been fixed on Linux. On Linux, `posix_memalign` is intercepted and
overridden by `asan_posix_memalign`, but that's not the case on macOS.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>