Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 13 Mar 2000 00:59:27 +0000
From:      Paul Richards <paul@originative.co.uk>
To:        Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
Cc:        keramida@ceid.upatras.gr, John Polstra <jdp@polstra.com>, current@FreeBSD.ORG
Subject:   Re: MAX_UID ?
Message-ID:  <38CC3D6F.73152D6D@originative.co.uk>
References:  <38CAD957.3C839375@originative.co.uk> <200003120430.UAA49807@vashon.polstra.com> <38CB322D.D12ED0B0@originative.co.uk> <20000313015009.A5653@hades.hell.gr> <38CC30FB.FC417909@originative.co.uk> <200003130018.TAA32652@khavrinen.lcs.mit.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
Garrett Wollman wrote:
> 
> <<On Mon, 13 Mar 2000 00:06:19 +0000, Paul Richards <paul@originative.co.uk> 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 majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?38CC3D6F.73152D6D>