cvs commit: src/sys/dev/en midway.c

Bruce Evans bde at
Thu Aug 7 05:59:44 PDT 2003

> On Wed, 6 Aug 2003, Andrew Gallatin wrote:
> AG>Hartmut Brandt [harti at] wrote:
> AG>> harti       2003/08/06 04:30:53 PDT
> AG>>
> AG>>   FreeBSD src repository
> AG>>
> AG>>   Modified files:
> AG>>     sys/dev/en           midway.c
> AG>>   Log:
> AG>>   Print an array index that is computed as ptrdiff_t with %tu.
> AG>
> AG>I don't understand why, but this breaks the sparc64 and alpha tinderboxes.
> AG>See
> AG>
> Not really. The breakage was earlier when the ptrdiff_t was printed via
> %d. David O'Brien fixed that by converting to long and using %ld. The
> above commit now uses the knowledge that the difference is actually an
> array index and therefor uses %tu. The tinderbox log file seems to be from
> yesterday before David's fix.

It also uses the knowledge that the difference is non-negative.  Why not
just print the difference as it is using the natural format %td?  This
makes no difference if the, uhm, difference is non-negative, but avoids
undefined behaviour if the difference is somehow negative.

Printing -1 using %tu on i386's gives an interesting example of the
undefined behaviour that results when a negative value is printed using
an unsigned format.  I expected the result UINT_MAX (2^32-1), but the
actual result is UINTMAX_MAX (2^64-1).  This is because the implementation
represents numbers using "uintmax_t ujval" for the %tu and %td formats,
so it represents -1 as UINTMAX_MAX, and then it just prints this value.


More information about the cvs-src mailing list