Subject: Re: pkg_select upgrade
To: Jachym Holecek <freza@liberouter.org>
From: David Laight <david@l8s.co.uk>
List: tech-pkg
Date: 03/17/2005 07:26:59
On Thu, Mar 17, 2005 at 07:29:41AM +0100, Jachym Holecek wrote:
> > Build failed on NetBSD/amd64.
> >
> > [...]
> >
> > I think we have two options.
> > Casting a variable to int in pkgselect source code or in ctype.h
> >
> > Option #1 would be like this:
> > In ftpio.c file,
> > - if (ftprc && isdigit(buf[match.rm_so+1]))
> > + if (ftprc && isdigit((int)buf[match.rm_so+1]))
> >
> > And here is option #2:
> > In /usr/src/include/ctype.h file,
> > -#define isdigit(c) ((int)((_ctype_ + 1)[(c)] & _N))
> > +#define isdigit(c) ((int)((_ctype_ + 1)[(int)(c)] & _N))
>
> isdigit(3) says the prototype is "int isdigit(int c);", so #1 would seem
> correct.
No, it is completely wrong and the VERY reason that gcc gives a warning
in this case.
The domain of all the isxxx() functions is EOF plus all the values of
unsigned char, typically -1..255. So if your signed char buf[n] contains
a negative value then the wrong things happen unless you cast to
unsigned char first.
Remember that isalpha() can be valid for -ve chars.
Of course, things will go terribly wrong if isdigit() returns non-zero
for anything other that '0'..'9'.
David
--
David Laight: david@l8s.co.uk