<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63326>63326</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang] Unsafe pointers and C standard issues
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
luc0x61
</td>
</tr>
</table>
<pre>
The following short code exploits **three** possible issues with warnings and errors:
``` lang-c
/// \file unsafe.c
// clang -std=c11 -Weverything unsafe.c -o unsafe.exe
#include <stddef.h>
static int goo (int * pi, size_t a)
{
return pi[a];
}
int main (int argc, char *argv[])
{
(void)argc;
(void)argv;
int goz[4] = { 0, };
return goo(goz, 0);
}
```
Compiling on Windows 11 pro x64, but with the standard x86 installer (released Clang/LLVM 16.0.6, "LLVM-16.0.6-win32.exe"):
```
# clang --version
clang version 16.0.6
Target: i686-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files (x86)\LLVM\bin
# clang -std=c11 -Weverything unsafe.c -o unsafe.exe
unsafe.c:5:24: warning: 'pi' is an unsafe pointer used for buffer access
[-Wunsafe-buffer-usage]
static int goo (int * pi, size_t a)
~~~~~~^~
unsafe.c:7:12: note: used in buffer access here
return pi[a];
^~
unsafe.c:14:13: warning: mixing declarations and code is incompatible with
standards before C99 [-Wdeclaration-after-statement]
int goz[4] = { 0, };
^
2 warnings generated.
```
1. Looks like I can't pass a generic pointer and do any arithmetics on it without the unsafe pointer warning (lines 5, 7): am I missing anything?
2. I requested C11 standard, but still receive C99 warning (line 14): does it make any sense?
3. Note that if I delete/comment the `#include` line there is no error/warning on `size_t` missing definition, compilation goes smooth
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVk-P27gO_zTKhXBgS7HjHHLInwYYoO_hHfq2x4Vi07a2spSV5EzaQz_7gpadSaZz2RqGLYgi-SP1IyXpvWoN4pble5YfF3IInXVbPVTprcgWZ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