[cfe-dev] Don"t work Clang Static Analyzer

Alexander * via cfe-dev cfe-dev at lists.llvm.org
Thu Aug 17 03:09:30 PDT 2017


Hello.
Today there was a case when analyzing the software (test.cpp) by Clang Staic Analyzer (CSA).
The following code contains the BUG, that involves using an uninitialized variable.

test.cpp:

include <iostream>
using namespace std;
int main(){
int i,k[1];
char str[5]={'a','b','c','d','e'};
for (i=0; i<4 ;i++)
{
    if (i==5) k[0]=3;
}
cout<<"k[0]="< <k[0] <<"\n";
cout<<str[ k[0] ]<<"\n";
return 0;
}

Analysis using CSA (by "scan-build g++ test.cpp -o test.out") does not detect the BUG.
If the number of loop iterations is reduced to 3, the BUG is detected.

W hat is the problem?
How to fix it?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170817/775b7751/attachment.html>


More information about the cfe-dev mailing list