|
PC-lint/FlexeLint Output |
Reference Manual Explanation |
Home
bug551.cpp
1 static unsigned word_length = 0;
2
3 unsigned maxr( unsigned u, unsigned len )
4 {
5 unsigned n = 0, m;
6 unsigned lowbit = u & 1;
7
8 if( len == 0 ) return 0;
9 while( (u & 1) == lowbit && n < len )
10 { u >>= 1; n++; }
11 m = maxr( u, len-n );
12 return n > m ? n : m;
13 }
14
15 /* max_run(u) returns the maximum run of 0's or 1's in u */
16 unsigned max_run( unsigned u )
17 {
18 unsigned w = ~0u;
19 while( w ) { word_length++; w >>= 1; }
20 return maxr( u, w );
21 }
|
The programmer wrote a "wonderful" algorithm to determine the length
of the maximum run of 0's or 1's in a word. Unfortunately there
is a fatal flaw that renders his algorithm useless. Can you spot it?
bug551.cpp lint Output
--- Module: bug551.cpp
--- Wrap-up for Module: bug551.cpp
Warning 551: Symbol 'word_length' (line 1, file bug551.cpp) not accessed
Reference Manual Explanation
551 Symbol 'Symbol' (Location) not accessed -- A variable (declared
static at the module level) was not accessed though the variable
was referenced. This means that the value of a variable was never
used. Perhaps the variable was assigned a value but was never
used. Note that a variable's value is not considered accessed by
autoincrementing or autodecrementing unless the autoincrement/decrement
appears within a larger expression, which uses the resulting value.
The same applies to a construct of the form: var += expression. If
an address of a variable is taken, its value is assumed to be accessed.
An array, struct or union is considered accessed if any portion thereof
is accessed.
If you have comments or questions about this bug, please post them to
our Discussion Forum
|