Linting Malloc (Was: Re: Need help with pointer to array[][])
ries at trwrb.UUCP
ries at trwrb.UUCP
Thu Mar 12 04:45:03 AEST 1987
In article <5347 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:
[... discussions on dynamically allocating arrays deleted ...]
>>
>> fnames = (char (*)[16][32])malloc(16*32*sizeof(char));
>>
[.. more deletions ...]
>Of course, proper paranoia also includes checking the return
>value from malloc():
>
> if ((fnames = (char (*)[32]) malloc(16 * sizeof (char [32))) == NULL)
> ... /* handle out of memory error */
>
>Another annoying nit is that malloc() takes an unsigned argument,
>while sizeof has type `size_t', which is not necessarily unsigned
>(it is signed in 4BSD), requiring yet more casts. (I would rather
>have an unsigned `size_t'.)
>--
>In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept
I have followed the discussion because of the comments on de-
linting and portability. Maybe one of the linting experts can
comment on the following case.
I noticed that while practicing de-linting the "filter" code in
the latest release of Dave Taylor's "ELM" mailer, the "parse.c"
code has several lines of the type:
if ((cond = (struct condition_rec *)
malloc(sizeof(struct condition_rec))) == NULL) {
(void) fprintf(stderr,"couldn't malloc first condition rec!\n");
return(-1);
}
where:
char *malloc();
struct condition_rec *cond;
lint (Pyramid 98X, 3.1 DualOSx, BSD Universe):
"warning: possible pointer alignment problem"
llib-lc:
char * malloc(n) unsigned n; {static char c; return(&c);}
Summary: Several gyrations of trying to get lint to shut up
hasn't. I there a way to get lint to pass this, make
this "more" portable, or ?.
Marc A. Ries
sdcrdcf!---\
ihnp4!------\----- trwrb! --- ries
--
Marc A. Ries
sdcrdcf!---\
ihnp4!------\----- trwrb! --- ries
More information about the Comp.lang.c
mailing list