size_t

david.f.prosser dfp at cbnewsl.ATT.COM
Thu Jul 6 06:49:57 AEST 1989


In article <971 at tukki.jyu.fi> tarvaine at tukki.jyu.fi (Tapani Tarvainen) writes:
>Something related which I would call a bug is the behaviour of
>calloc() that e.g., calloc(1000,1000) won't give an error or NULL but
>silently truncates the product to 16960 (== 1000000 && 0x0ffff) and
>allocates that amount.  What does the pANS say about overflow handling
>in this situation?
>-- 
>Tapani Tarvainen                 BitNet:    tarvainen at finjyu
>Internet:  tarvainen at jylk.jyu.fi  -- OR --  tarvaine at tukki.jyu.fi

There is a general statement in section 4.1.6 for the arguments to the
library functions.  It allows undefined behavior in the library if a
function is passed arguments with invalid values, or values outside of
the function's domain.  Since calloc() must produce an object with no
more bytes than can be counted in a size_t, a pair of arguments that,
while individually are valid, cannot be multiplied and produce a result
that fits in a size_t, will result in undefined behavior for calloc().
If there were some special part of calloc()'s description that
constrained the function to handle this case, the behavior would be
otherwise.

Dave Prosser	...not an official X3J11 answer...



More information about the Comp.std.c mailing list