I am using clang static analyzer 4.0.0. For the following example
int fun(){
int aa = 1,bb = 0;
int cc = aa/bb; // 1) devide by zero. // Reported by clang
int *pt = nullptr;
int a = *pt; // 2) null pointer dereference. // NOT Reported by clang
int b;
int c = a + b; // 3) Unused initialization. // Reported by clang
return cc;
}
Clang static analyzer reports only two issues 1 and 3 and skips issue 2.
Whereas if I changed the order of issue like this
int fun(){
int *pt = nullptr;
int a = *pt; // 1) null pointer dereference. // Reported by clang
int aa = 1,bb = 0;
int cc = aa/bb; // 2) devide by zero. // NOT Reported by clang
int b;
int c = a + b; // 3) Unused initialization. // Reported by clang
return cc;
}
then clang static analyzer reports 1 and 3 and skips 2.
I am running clang static analyzer with this command
clang-check.exe -analyze D:\testsrc\anothercpp.cpp
This is very inconsistent behavior. No matter in what order the issues are, one of the issue get skipped. Also, I checked this scenario with clang 5.0.1 only to yield same results.
Does anybody have any idea why this is happening with static analyzer?
Thanks in advance.
-Hemant