bug in params.c

Christopher R. Hertel crh at nts.umn.edu
Tue Oct 17 17:08:27 GMT 2000


[Charset iso-8859-1 unsupported, filtering to ASCII...]
> Chris,
> 
> On Mon, 16 Oct 2000 11:27:26 -0500 (CDT), Christopher R. Hertel wrote:
> 
> >>         /* be sure to return chars >127 as positive values */
> >>       return (int)( *(f->p++) & 0x00FF );
> 
> Shouldn't this be
> 
>     return (int)( *(f->p++) & 0x007F );
> 
> ?

No, it shouldn't.  We want the full range of one-byte values to be seen as
unsigned.  0x007F translates to: 0111 1111, thus we lose the top bit and
everything in the 128..255 range gets mangled.  By ANDing with a short
(0000 0000 1111 1111) we return a value that is not sign-extended, and
thus positive. 

For example, the u-umlaut has a value of 252 (IIRC).  That would be 0xFC 
or 1111 1100.  If you take that as a two's compliment value you get -4, 
but if you AND it with 0x00FF you get 0x00FC which is a positive value: 
252 again.  If you AND it with 0x007F you would get 0111 1100 which is 
0x7C or '|'.  Nothing to do with the u-umlaut.

Of course, in the EatComments() function all we care about is bypassing
comments so we can parse real stuff.  Still, other functions use the
mygetc() call so we want it to be correct. 

There are probably a dozen ways to do this.  I'm not sure off hand which
would be the fastest, but comment processing doesn't eat a lot of time
anyway.  I suppose you could also do:

    return (int)*((unsigned char *)(f->p++));

Chris -)-----

-- 
Christopher R. Hertel -)-----                   University of Minnesota
crh at nts.umn.edu              Networking and Telecommunications Services

    Ideals are like stars; you will not succeed in touching them
    with your hands...you choose them as your guides, and following
    them you will reach your destiny.  --Carl Schultz





More information about the samba-technical mailing list