Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 9 Jun 1995 18:12:14 +1000
From:      Bruce Evans <bde@zeta.org.au>
To:        bugs@FreeBSD.org, dillon@best.com
Subject:   Re: connect() bug found and fixed (uninitialized pointer)
Message-ID:  <199506090812.SAA23942@godzilla.zeta.org.au>

index | next in thread | raw e-mail

>    * have noticed that sprintf() seems to need its arguments
>      cast to the exact type spected by the '%' control
>      elements, as reported in warnings if you compile something
>      -Wall (you have no warnings if you do not use -Wall).  
>      Integer-type to integer-type casts are required... for 
>      example, char to int for %d, int to char for %c, time_t, 
>      gid_t, etc... not sure why.  This broke wu-ftpd and a 
>      couple of other programs.  As best as I can tell,
>      something gets confused and the parameter offsets
>      get skewed, causing corruption when a bad pointer
>      (due to the skew) is dereferenced.

Runtime problems are most likely caused by %d or %ld format specifiers
mismatched with quad_t arguments, e.g., off_t's.  quad_t's should be
printed in format %qd.  Casts shouldn't normally be used except for
pointers.  Pointer types should be cast to (void *) and printed in
format %p.  -Wall finds most mismatches to give you some chance of
detecting int vs. long mismatches but it is sloppy about pointers.

Bruce


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199506090812.SAA23942>