[splint-discuss] New user
Michael Wojcik
Michael.Wojcik at microfocus.com
Fri Aug 8 07:54:06 PDT 2008
> From: splint-discuss-bounces at cs.virginia.edu
> [mailto:splint-discuss-bounces at cs.virginia.edu] On Behalf Of
> Olivier FAURAX
> Sent: Friday, 08 August, 2008 09:51
>
> I try to use splint, but I encounter parse errors everytime.
> The last time, it was on this line : void* y = (void*)
> malloc(x); What is difficult to parse here ?
Nothing. The following is passed by splint 3.1.1 with no errors or
warnings, using the default settings:
-----
#include <stdlib.h>
static void foo(size_t x) {
void *y = (void*) malloc(x); /* your example */
free(y);
}
int main(void) {
foo(1);
return 0;
}
-----
So presumably it is something else in your code, likely on a previous
line, which is causing the problem.
Note that casting the return value of malloc is bad practice. If a
correct declaration for malloc is in scope, its return type is void *,
which can be converted to any object pointer type on assignment. Casting
the return value of malloc only serves to hide the error of failing to
have a correct declaration in scope.
(The one exception is for code that needs to be compiled as both C and
C++. This is not common.)
--
Michael Wojcik
Principal Software Systems Developer, Micro Focus
More information about the splint-discuss
mailing list