|
PC-lint/FlexeLint Output | Reference Manual Explanation | Home Page bug432.c
In this example the user creates a string-allocation function called salloc() and tests its behavior. The test appears to go well and yet salloc() contains a fatal flaw. Can you find it?
bug432.c lint Output
--- Module: bug432.c
_
char *ret = (char *) malloc( strlen(s+1) );
bug432.c(7) : Warning 432: Suspicious argument to malloc
Reference Manual Explanation
432 Suspicious argument to malloc -- The following pattern
was detected:
malloc( strlen(e+1) )
where e is some expression. This is suspicious because it
closely resembles the commonly used pattern:
malloc( strlen(e)+1 )
If you really intended to use the first pattern then an
equivalent expression that will not raise this error is:
malloc( strlen(e)-1 )
|
Previous Bug - Bug #550 - July 2001