#17 netcat_flag_count() fix.

open
nobody
5
2004-11-17
2004-11-17
No

The interior loop of netcat_flag_count() (which you've
flagged with "FIXME") is wrong. The (or a list "a")
correct version is:

ret += (c & 1);
c >>= 1;

Now, the *real* problem is that you're using 'char'
instead of
'unsigned char'. I suspect that on a machine that makes
'char' equivalent to 'signed char', your version did
something that worked, at least most of the time.
However, on AIX, which uses 'char == unsigned char'
(completely withing the C standard), 'c >> 7' just
throws away the lower 7 bits.

Regards,
Steve

Discussion

  • Nobody/Anonymous

    Logged In: NO

    klc_click.hack@hotmail.com

     
  • Nobody/Anonymous

    Logged In: NO

    Hello,
    I've found the same problem on LynxOS machine.
    I've made a workaround in the same spirit. "ret+=" and not "ret-="
    Regards
    Philippe

     
  • Anonymous - 2007-03-04

    Logged In: YES
    user_id=1125065
    Originator: NO

    Hi,

    same for me on 2003 Apple Powerbook G4 running gentoo. I made a patch fixing the issue, please apply.

    Mattias

     
  • Anonymous - 2007-03-04

    Logged In: YES
    user_id=1125065
    Originator: NO

    Here is the patch (I couldn't figure out how to attach it to the bug :-()

    --- bad/netcat-0.7.1/src/flagset.c 2003-12-10 17:18:07.000000000 +0100
    +++ good/netcat-0.7.1/src/flagset.c 2007-03-04 17:38:10.000000000 +0100
    @@ -134,7 +134,7 @@

    int netcat_flag_count(void)
    {
    - register char c;
    + register unsigned char c;
    register int i;
    int ret = 0;

    @@ -154,8 +154,8 @@
    Assumed that the bit number 1 is the sign, and that we will shift the
    bit 1 (or the bit that takes its place later) until the the most right,
    WHY it has to keep the wrong sign? */
    - ret -= (c >> 7);
    - c <<= 1;
    + ret += (c & 1);
    + c >>= 1;
    }
    }

     
  • Nobody/Anonymous

    Logged In: NO

    Also netcat_flag_count returns negative values on arm (nokia N800)

    thos solution seems the right one

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks