qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] Printing bogus values in ne2000_asic_ioport_read()/ ne2


From: Chris Wilson
Subject: Re: [Qemu-devel] Printing bogus values in ne2000_asic_ioport_read()/ ne2000_receive()
Date: Wed, 1 Mar 2006 23:22:28 +0000 (GMT)

Hi Umamaheswararao,

In ne2000_receive(), I copied the packet received to a
static char [] and printed the packet using
static void print_packet(char *s, int len)
{
 int i,j;
 for (i=0;i<len;i++) {
     if (i%20 == 0)
         printf("\n");
     printf("%02x ", s[i]);
 }
         printf("\n");
}
And some bytes it prints as fffffffff<last byte>
instead of just the last byte.
For eg:
52 54 00 12 34 56 00 ffffffff 4f 0a 46 05 08 00 45 00
00 ffffff80 00 00
40 00 40 01 ffffffbc 2b ffffffc0 ffffffa8 fffffffe
fffffffe ffffffc0 ffffffa8 ff

You are using signed chars, and they are being sign-extended to signed ints, which fills the remaining (upper) bits with 1's. When formatted as hex, they no longer fit into two characters, because the upper bits are not zeroes. So printf prints the full 32 bits.

Try using "unsigned char *s" in the prototype instead of just "char *s" and see if that helps.

Cheers, Chris.
--
_ ___ __     _
 / __/ / ,__(_)_  | Chris Wilson <0000 at qwirx.com> - Cambs UK |
/ (_/ ,\/ _/ /_ \ | Security/C/C++/Java/Perl/SQL/HTML Developer |
\ _/_/_/_//_/___/ | We are GNU-free your mind-and your software |





reply via email to

[Prev in Thread] Current Thread [Next in Thread]