Garrett Wollman wrote:
>
> <<On Mon, 13 Mar 2000 00:06:19 +0000, Paul Richards <[EMAIL PROTECTED]> said:
>
> > We could create a new include file that we use for constants that are
> > related to FreeBSD specific types or we can agree on a coding style for
> > performing bounds checking using tricks like ((uid_t)0-1)
>
> Or we can do it the right way, by assigning to a variable of the
> correct type and checking that the value remains unchanged.
I'm not just trying to determine whether a value fits into a type, I'm
also trying to find out what the maximum value the type can hold is.
e.g. in the following code snippet
id = strtoul(p, (char **)NULL, 10);
if (errno == ERANGE) {
warnx("%s > max uid value (%lu)", p, ULONG_MAX);
return (0);
}
you also have to print out the maximum value. Not an uncommon
requirement for error reporting.
You're solution doesn't help with the second part.
What I'm looking at is the following.
id = strtoul(p, (char **)NULL, 10);
if ((errno == ERANGE) || (id >= ((uid_t)0-1))) {
warnx("%s > max uid value (%lu)", p, ((uid_t)0-1));
return (0);
}
or the alternative
id = strtoul(p, (char **)NULL, 10);
if ((errno == ERANGE) || (id >= UID_MAX)) {
warnx("%s > max uid value (%lu)", p, UID_MAX);
return (0);
}
When you see it written out like that the latter is a lot more
informative. It also provides the flexibility to limit the parameters
max value even if the type allows it to be larger. This is of particular
significance to UIDs which are currently limited to a far smaller value
than would fit in a uid_t.
Paul.
To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message