On Tue, 15 Dec 2015, Ralf Junker wrote:
> So for INT32 overflow checking, it should be possible for all OS and compilers
> to simply test the following:
>
> for strtol(): li >= INT32_MAX || li <= INT32_MIN
> for strtoul(): uli >= UINT32_MAX
> (or uli >= INT32_MAX, for consistency).
>
> I hope this makes more sense. If not, let's simply forget about it. Your code
> works well as is.
Yes, and indeed that looks right. However, I did it the way I did in
case some very picky pedantic compiler complains about testing for
greater than the maximum value of something.
Actually, come to think of it, your test is not always totally right in
some edge cases. On a 64-bit system, a value of UINT32_MAX (which is
less than ULONG_MAX) is actually OK. I agree that this doesn't really
matter!
Philip
--
Philip Hazel