Garrett Cooper wrote this message on Fri, Oct 31, 2014 at 14:30 -0700: > On Oct 28, 2014, at 4:33, Bruce Evans <b...@optusnet.com.au> wrote: > > > On Tue, 28 Oct 2014, [utf-8] Dag-Erling Smørgrav wrote: > > > >> Bruce Evans <b...@optusnet.com.au> writes: > >>> Dag-Erling Smørgrav <d...@des.no> writes: > >>>> This is a bug on all platforms, and both clang and (recent) gcc > >>>> should complain about it. That printf() call will print garbage. > >>> No, this is only a bug on 32-bit arches. The is is SSIZE_MAX. > >> > >> If you mean "it only has consequences on 32-bit arches", then I agree - > >> but it is still a bug to pass an int to %jd. > > > > This is machine-dependent. intmax_t may be int. The only requirement > > on intmax_t is that it can represent any value of any signed integer > > type. This is possible if the largest integer type is 64 bits (the > > smallest permitted largest type) and int is also 64 bits (and there > > are no complications for padding bits). intmax_t can even be signed > > char if that is wide enough (not in POSIX starting 10-15 years ago, > > since signed char is now required to be 8 bits. It is weird for > > intmax_t to have the lowest rank (not counting Bool), but FreeBSD uses > > this loophole to make it have second highest rank on 64-bit arches. > > Indeed. For some giggles, look at this bug: > https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=191674 ("printf("%tu", > (intmax_t)-1) returns UINT64_MAX on i386, not UINT32_MAX?).
That isn't surprising.. because you're sign extending -1 via intmax_t... Even if you didn't mix unsigned and signed in your printf, and casted to uintmax_t, you'd still get UINT64_MAX... This is just how casting of signed numbers work and conversion from signed to unsigned... The bug (from 191674) is in [SU]JARG casting ptrdiff_t to intmax_t if anywhere... It should be cast to the correct intXX_t sized value instead.. In the SJARG case, a simple cast to ptrdiff_t is sufficient.. Now bde will have better idea on the UJARG case, but that needs to go be casted to uintXX_t, and no further casting is needed... -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not." _______________________________________________ svn-src-head@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"