[cfe-dev] one suggestion for Clang static analyzer
Richard Smith
richard at metafoo.co.uk
Sun Aug 10 22:44:52 PDT 2014
Note that p is an int* not a char*.
On 10 Aug 2014 22:43, "David Blaikie" <dblaikie at gmail.com> wrote:
> At a glance I don't know why the program is crashing. Could you explain it?
> On Aug 10, 2014 6:49 AM, "hw" <dtletmedn at gmail.com> wrote:
>
>> Dear All,
>>
>> I am wondering if Clang static analyzer could extend to find out the bug in the following code.
>>
>> #include <stdio.h>
>>
>> #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
>> }
>> }
>>
>>
>> Best,
>>
>> hw
>>
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140810/6ad3f792/attachment.html>
More information about the cfe-dev
mailing list