<div dir="ltr"><pre style="white-space:pre-wrap"><code>Dear All,</code></pre><pre style="white-space:pre-wrap"><span style="font-family:arial">I am wondering if Clang static analyzer could extend to find out the bug in the following code.</span><br>
</pre><pre style="white-space:pre-wrap"><span style="font-family:arial">#include </span><span style="font-family:arial"><stdio.h></span><br></pre><pre style="white-space:pre-wrap"><code>#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define SIZE 1024*1024*1024
int main()
{
printf("%ld,%ld,%ld\n",sizeof(int),sizeof(long),sizeof(size_t));//output 4,8,8
printf("%ld\n",SIZE); //output 1073741824
int *p = (int*)malloc(SIZE);
if(!p){
perror("malloc");
exit(1);
}
memset(p,0,SIZE); //this works fine
size_t i=0;
for(;i<SIZE;++i){
p[i] = 10; //gdb shows when crashed i = 268436476
}
}</code></pre><pre style="white-space:pre-wrap"><code><br></code></pre><pre style="white-space:pre-wrap"><code>Best,</code></pre><pre style="white-space:pre-wrap"><code>hw</code></pre></div>