Subject: Re: libkern's strtoul()
To: None <tech-kern@netbsd.org>
From: Allen Briggs <briggs@wasabisystems.com>
List: tech-kern
Date: 06/04/2003 10:20:10
On Wed, Jun 04, 2003 at 09:23:08AM +0100, David Laight wrote:
> How about a few bugs/improvements?

Sure!

> > 		if (c >= '0' && c < ('0' + min(base, 10)))
> I think the min() is unnecessary, c <= '9' will do.
> The 'c >= base' lower down will stop 8 being an octal digit.

You're absolutely correct.

> > 	if (neg && any > 0)
> > 		acc = -acc;
> Does that DTRT for overlarge -ve numbers?

I think it does, but please define "overlarge".  Do you have a
specific concern?

> I'm not sure what the standard requires?

Well, we're kind of outside "the standard" in libkern.  For instance,
I'm not sure what the best overflow error behavior is.  In libc, you
return ULONG_MAX and set errno = ERANGE.  In the kernel, of course,
we don't have errno.  The existing libkern behavior is to return
ULONG_MAX, but set the endptr to the passed-in string.  This doesn't,
however, tell you where the number might end.  Of all of the uses of
strtoul in the kernel, only one file actually bothers to check for
errors!

So I've modified the implementation I posted to get rid of the min()
and to return ULONG_MAX with the endptr set to the passed-in string
in the overflow case.

Any other comments?

-allen

-- 
 Allen Briggs                     briggs@wasabisystems.com
 Wasabi Systems, Inc.             http://www.wasabisystems.com/