[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: at least 260 packages broken on arm, powerpc and s390 due to wrong assumption on char signedness

On Sun, Dec 30, 2001 at 11:09:50PM -0500, Colin Walters wrote:
> On Sun, 2001-12-30 at 17:02, Julian Gilbey wrote:
> > This package is correct as is, and the warning is harmless; the line
> > of code involved is:
> > 
> > return (c<0||c>255)? unexpected_char: icode[c];
> > 
> > where c is a char expected to be in the normal range (0<=c<=127).  All
> > the chars used in this code (AFAICT) are in this range.
> This still says to me there is likely a logic error in the code; if the
> authors thought it was possible for c to take on a negative value at
> some point, then it should be declared signed.  Otherwise, why not just
> declare it unsigned and remove the test for c < 0?

I believe that the author (Knuth) presumably thought "c should only be
between 0 and 127, probably not even that far, and we're using c as an
array index, where we've only allocated 256 chars for this array.  As
char might be a signed char, c could feasibly be less than 0, and
there's a small possibility that char could be some weird wide
character thing, so c could feasibly be greater than 255, we'll
perform the checks just check to be on the safe side."  Defensive



     Julian Gilbey, Dept of Maths,             Debian GNU/Linux Developer
      Queen Mary, Univ. of London         see http://people.debian.org/~jdg/
   http://www.maths.qmul.ac.uk/~jdg/           or http://www.debian.org/
        Visit http://www.thehungersite.com/ to help feed the hungry
                 Also: http://www.helpthehungry.org/

Reply to: