One year of Coverity work
One year of Coverity work
Posted Aug 22, 2014 14:28 UTC (Fri) by etienne (guest, #25256)Parent article: One year of Coverity work
I know some developers see that has bad practice, but I use it to attract attention about a variable - when that variable is initialized and used in only some code-path.
The "design pattern" is basically:
void fct(...) {
int var = var;
if (test1) var = 42;
some_common_function();
if (test2) anotherfct (var);
}
The point is that you shall never use the variable "var" without initializing it, but in this case the compiler will not check for you - "var = var;" is just a "take care" indication to the reader and not a real initialisation.
The other point is that it is not logical to always initialize "var" to a dummy value - there may not be any dummy value available, and usually it would be an error to use that dummy value considering the algorithm.
So when a maintainer see "int var = var;", he will know that "test2" has to be either identical to "test1", or more restrictive than "test1".
I have see too many bug created by bug-fixes applied to just "test1"...
