cvs commit: src/lib/libc/stdlib getenv.c

Dag-Erling Smørgrav des at des.no
Sun Sep 23 06:35:57 PDT 2007


Bruce Evans <brde at optusnet.com.au> writes:
> On Sat, 22 Sep 2007, [utf-8] Dag-Erling Smørgrav wrote:
> > s/to remove the warning/to actually work/
> Please be precise :-).
> s/to remove the warning ... on 64-bit platforms/to avoid undefined behaviour
> on platforms where size_t is not u_int, and to avoid having to make a
> delicate analysis to show that the behaviour is defined and correct on
> all other platforms/.
>
> Delicate analysis:
> - size_t is always an unsigned type, but the required type is int, so
>   size_t is never compatible with the required type.
> - on platforms where size_t is smaller than int, the arg type is
>   nevertheless compatible with int, since warnx() is variadic and the
>   arg is one of the variadic args; the default promotions thus apply
>   and the arg is passed as an int whether or not you cast it explicitly
>   to int (but casting it to a type larger than int would break it).
>   FreeBSD doesn't support any platforms in this class.
> - on platforms where size_t is u_int, the arg is passed as a u_int.
>   The analysis for this case is too delicate to give in full here.

you left out the case where size_t is larger than unsigned int, i.e. all
64-bit platforms.  Even if the stack is aligned to the size of size_t,
you will get interesting results on a big-endian system.

DES
-- 
Dag-Erling Smørgrav - des at des.no


More information about the cvs-src mailing list