[Cryptography] GCC bug 30475 (was Re: bounded pointers in C)
Viktor Dukhovni
cryptography at dukhovni.org
Fri Apr 25 12:23:03 EDT 2014
On Fri, Apr 25, 2014 at 07:05:15AM -0400, Jerry Leichter wrote:
> It's easy to determine the maximum value of an *unsigned* type.
> It's not clear to me now that there is any portable way to determine
> the maximum value of a *signed* type.
Indeed, nothing obvious comes to mind. My work-around requires
C99 intmax_t. I do all arithmetic for off_t using safe intmax_t
arithmetic instead (which comes with INTMAX_MAX), and then at the
end make sure that casting to off_t does not truncate the value:
off_t mumble(off_t input, ...)
{
intmax_t tmp = input;
off_t result;
/* safe intmax_t arithmetic using tmp */
result = (off_t) tmp;
if (result != tmp)
/* error */
return result;
}
This is a pain. And as I mentioned, I'd like to avoid a C99
dependency, but don't see any portable way to do that.
--
Viktor.
More information about the cryptography
mailing list