[ENet-discuss] Nasty bug in packet fragmentation receive code

Lee Salzman lsalzman1 at cox.net
Thu Apr 7 15:29:01 PDT 2005


Wow, I wonder when that bug crept in. Oh well, fixed in CVS now.

Tibor Klajnscek wrote:

> Hi everyone!
>
> Packet fragmentation seems to be totally broken.
> I have the sources from the CVS (updated today).
>
> The following code is broken (in protocol.c):
>
> if ((startCommand -> fragments [fragmentNumber / 32] & (1 << 
> (fragmentNumber & 32))) == 0)
>    {
>       -- startCommand -> fragmentsRemaining;
>
>       startCommand -> fragments [fragmentNumber / 32] |= (1 << 
> (fragmentNumber & 32));
>
>       if (fragmentOffset + fragmentLength > startCommand -> packet -> 
> dataLength)
>         fragmentLength = startCommand -> packet -> dataLength - 
> fragmentOffset;
>
>       memcpy (startCommand -> packet -> data + fragmentOffset,
>               (enet_uint8 *) command + sizeof (ENetProtocolSendFragment),
>               fragmentLength);
>    }
>
> This is what works for me:
>
>    int byteoffset = 0;
>    int bitoffset = 0;
>
>    // ..... other code
>
>    byteoffset = fragmentNumber / 32;
>    bitoffset = fragmentNumber % 32;
>
>    if ((startCommand -> fragments [byteoffset] & (1 << bitoffset)) == 0)
>    {
>       -- startCommand -> fragmentsRemaining;
>
>       startCommand -> fragments [byteoffset] |= (1 << bitoffset);
>           if (fragmentOffset + fragmentLength > startCommand -> packet 
> -> dataLength)
>         fragmentLength = startCommand -> packet -> dataLength - 
> fragmentOffset;
>
>       memcpy (startCommand -> packet -> data + fragmentOffset,
>               (enet_uint8 *) command + sizeof (ENetProtocolSendFragment),
>               fragmentLength);
>    }
>
> Please reply to this message to let me know if I did something wrong and
> if the original code should work.
>
> Best regards,
> Tibor
>
>------------------------------------------------------------------------
>
>_______________________________________________
>ENet-discuss mailing list
>ENet-discuss at cubik.org
>http://lists.cubik.org/mailman/listinfo/enet-discuss
>  
>



More information about the ENet-discuss mailing list