Graphics Programs Reference
In-Depth Information
The code path shown by the analyzer lines is as follows:
1. The variable
count
is created and not initialized.
2. The
if
statement fails, so
count
does not get a value.
3. The variable
count
is returned without being assigned a value.
You can fix this issue by initializing
count
to zero.
- (int)numberOfLines
{
int count;
int count = 0;
// Check that they are non-nil before we add their counts...
if (linesInProcess && completeLines)
count = [linesInProcess count] + [completeLines count];
return count;
}
Analyze this code again, and no issues will be reported now that
count
is always initial-
ized with a value.
When you analyze your code (which you will do on a regular basis because you are a
smart programmer), you'll see issues other than the one described here. Many times, we
see novice programmers shy away from analyzer issues because of the technical language.
Don't do this. Take the time to expand the analysis and understand what the analyzer is
trying to tell you. It will be worth it for the development of your application and for your
development as a programmer.