PC-lint/FlexeLint Output | Reference Manual Explanation | Home Page
1 #include <string.h>
2
3 void process( int *, int * );
4 #define N 100
5
6 void f( int n )
7 {
8 int *p, *q;
9 int i;
10
11 p = new int[ N*2 ];
12 q = new int[ N ];
13 if( !p || !q ) return;
14 if( n >= 0 ) memset( p, 1, N*2 );
15 else for( i = 0; i < N*2; i++ )
16 p[i] = i;
17 memset( q, 0, n );
18 process( p, q );
19 }
Calling this function has caused strange and erratic behavior. Can you spot the problem?
--- Module: bug671.cpp
_
memset( q, 0, n );
bug671.cpp(17) : Info 732: Loss of sign (arg. no. 3) (int to unsigned int)
bug671.cpp(17) : Warning 671: Possibly passing to function memset(void *,
int, unsigned int) a negative value (-1), arg. no. 3
_
}
bug671.cpp(19) : Warning 429: Custodial pointer 'p' (line 8) has not
been freed or returned
bug671.cpp(19) : Warning 429: Custodial pointer 'q' (line 8) has not
been freed or returned
671 Possibly passing to function Symbol a negative value (Integer),
Context -- An integral value that may possibly be negative is
being passed to a function that is expecting only positive values
for a particular argument. The message contains the name of the
function (Symbol), the questionable value (Integer) and the
argument number (Context). The function may be a standard
library function designed to accept only positive values such as
malloc or memcpy (third argument), or may have been identified by
the user as such through the -function or -sem options.
See message 422 for an example and further explanation.
Previous Bug - Bug #669 - November 1997
Next Bug - Bug # 1547 - January 1998