tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: detecting integer over/underflow



In article <20120304224807.f5f4c82f.cryintothebluesky%googlemail.com@localhost>,
Sad Clouds  <cryintothebluesky%googlemail.com@localhost> wrote:
>
>OK so given
>
>int32_t n32;
>uint64_t n64;
>int32_t n32_result;
>
>n32_result = (uint64_t)n32 + n64;
>
>Are you checking that
>
>1) 64-bit sum will not be truncated and will fit into 32-bit variable,
>or
>
>2) 64-bit sum will not overflow 64-bits before it is assigned (and
>possibly truncated) to 32-bit variable, or
>
>3) check both
>

Only 1)

christos



Home | Main Index | Thread Index | Old Index