JPacket.transferTo bug

Printer-friendly

I found a bug while writing some new test cases and having to use JPacket.transferTo(JPacket) to copy contents of one packet to another.

I was writing a neat routine to get a single packet out of a file by packet index, perfect as an example on the website so I'll add it in, but here is what happened. First packet is as received from the packet handler, the second a new packet that allocates a
2K memory block to hold the packet content.

JPacket shared = // from JPacketHandler
JPacket dst = new JPacket(2 * 1024); // Allocate memory

Next we copy contents of shared packet to dest.

shared.transferStateAndDataTo(dst);

And although everything seem to copy (I verified the contents of both shard and dst data and state buffers, the packet accessors were giving me real strange data.

Turns out that the packet_state_t structure wasn't being copied in its entirety. It has a variable number of header_t structures attached at the end and therefore its not a static size structure. I fixed it up in the scanner to properly update the state size field and to include the header_t[] memory as well.

So now every correctly copies over.