<p dir="ltr">Note that p is an int* not a char*.</p>
<div class="gmail_quote">On 10 Aug 2014 22:43, "David Blaikie" <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<p dir="ltr">At a glance I don't know why the program is crashing. Could you explain it?</p>
<div class="gmail_quote">On Aug 10, 2014 6:49 AM, "hw" <<a href="mailto:dtletmedn@gmail.com" target="_blank">dtletmedn@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<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>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div>