<HTML><BODY>Hello.<br><span id="result_box" lang="en"><span>Today there was a case when analyzing the software (test.cpp) by Clang Staic Analyzer (CSA).</span><br><span>The following code contains the BUG, that involves using an uninitialized variable.<br><span style="font-family: courier new,courier;"><br><strong>test.cpp:<br></strong><br>include <iostream></span><br><span style="font-family: courier new,courier;">using namespace std;</span><br><span style="font-family: courier new,courier;">int main(){</span><br><span style="font-family: courier new,courier;">int i,k[1];</span><br><span style="font-family: courier new,courier;">char str[5]={'a','b','c','d','e'};</span><br><span style="font-family: courier new,courier;">for (i=0;<span style="background-color: rgb(5, 132, 11);">i<4</span>;i++)</span><br><span style="font-family: courier new,courier;">{</span><br><span style="font-family: courier new,courier;"> <span style="background-color: rgb(5, 132, 11);"> if (i==5) k[0]=3;</span></span><br><span style="font-family: courier new,courier;">}</span><br><span style="font-family: courier new,courier;">cout<<"k[0]="<<span style="background-color: rgb(255, 255, 255);"><k[0]</span><<"\n";</span><br><span style="font-family: courier new,courier;">cout<<str[<span style="background-color: rgb(5, 132, 11);">k[0]</span>]<<"\n";</span><br><span style="font-family: courier new,courier;">return 0;</span><br><span style="font-family: courier new,courier;">}</span><br></span> <br><span></span></span><span id="result_box" lang="en"><span>Analysis using CSA (by "scan-build g++ test.cpp -o test.out") does not detect the BUG.<br></span> <span>If the number of loop iterations is reduced to 3, the BUG is detected.</span> <br><br>W<span>hat is the problem?<br></span> <span>How to fix it?</span></span><br><br><br></BODY></HTML>