hiding lint's ravings (was Re: FAQ - malloc array - clarify)

Doug McDonald mcdonald at aries.scs.uiuc.edu
Sun Sep 9 04:33:20 AEST 1990


In article <8086 at helios.TAMU.EDU> jdm5548 at diamond.tamu.edu (James Darrell McCauley) writes:
>How do you professionals deal with insignificant(?) ravings from
>lint (or other high quality C program verifiers) such as the 
>following:
>
>>test.c(x): warning: possible pointer alignment problem
>which was caused by the malloc in:
>
>>double **dmatrix(nr,nc)
>>int nr,nc;
>>{
>>  double **m = NULL;
>>
>>  m = (double **) malloc( (unsigned) nr * sizeof(double *) );
>>  if (!m) ...
>
>From what netlanders tell me, this warning is explanined as:
>(by Conor P. Cahill) 
>|>                         The problem is that malloc is defined
>|> as returning a pointer to char which has looser alignment requirements than
>|> pointer to pointer.  Since malloc guarrantees that the result is suitably 
>|> alligned for all data types, you can ignore this message.
>
>Well, I can just ignore warnings like this, but those who review
>my code (professors, employers, clients) are not likely to. It makes
>an bad impression and frankly, I find it a little embarrassing.


It is NOT embarrassing to you. It just plain a BUG in lint. Pure and
simple. Complain to the person that sold you the broken "lint".
A checker program really OUGHT to understand the rules of what it is
checking. One of those rules concersn alignments of the return
value of malloc.

Doug McDonald



More information about the Comp.unix.programmer mailing list