netcat_flag_count() fix.
The networking swiss army knife
Status: Beta
Brought to you by:
themnemonic
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
Logged In: NO
klc_click.hack@hotmail.com
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
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
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;
}
}
Logged In: NO
Also netcat_flag_count returns negative values on arm (nokia N800)
thos solution seems the right one