<html>
<head>
<base href="https://llvm.org/bugs/" />
</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 --- - __builtin_object_size(null_pointer) returns the wrong result"
href="https://llvm.org/bugs/show_bug.cgi?id=23277">23277</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>__builtin_object_size(null_pointer) returns the wrong result
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</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>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>danielmicay@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>This outputs (size_t)-1 in both cases with `gcc -O2` but clang gives 0 for the
second case:
#include <stdio.h>
int main(int argc, char **argv) {
printf("%zu\n", __builtin_object_size(NULL, 0));
void *p = NULL;
printf("%zu\n", __builtin_object_size(p, 0));
return 0;
}
This is broken with glibc's _FORTIFY_SOURCE implementation for nullable
parameters. It assumes that it can do comparisons like `object_size(buffer) <
copy_size` after handling the unknown case, but this can result in a false
positive with Clang. It's not a glibc bug because they're using GNU C as it is
defined by GCC, which is where this feature comes from.</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>