On Thu, Nov 12, 2009 at 10:46:47AM -0500, Mark Bucciarelli wrote:
> Hi,
> 
> Part 1:
> 
> How can I tell if casting a off_t (e.g, sb.st_size) to size_t risks
> an overflow?
> 

You have to check for overflows:

        if (sb.st_size > SIZE_MAX) {
                /* error */
                ...
        }
        size = sb.st_size;

> What about casting ptrdiff_to to a uint64_t or a long?
> 

same here

> The full table of all such possible integer type casts must be large
> (and full of dragons?).  How do you all keep it straight?
> 

I use the same type everywhere avoiding any conversions (and
checks).

-- Alexandre

Reply via email to