One year of Coverity work
One year of Coverity work
Posted Aug 22, 2014 17:18 UTC (Fri) by giraffedata (guest, #1954)In reply to: One year of Coverity work by etienne
Parent article: One year of Coverity work
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.
A more fundamental reason not to initialize "var" to a dummy value is that it makes the code harder to read. It makes it look like that dummy value is a legitimate value for "var" (after all, it is common for people to cram multiple pieces of information into a variable, so "-1" isn't necessarily a dummy value for a variable named "length"). And it makes it look like "var" is meaningful in the code before it is really set. And that makes it much harder for a reader of the code to detect true used-before-set bugs.
