]> git.tdb.fi Git - libs/net.git/commitdiff
Fix a length calculation bug in Protocol::dispatch
authorMikko Rasa <tdb@tdb.fi>
Sat, 10 Dec 2022 17:59:30 +0000 (19:59 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 10 Dec 2022 17:59:30 +0000 (19:59 +0200)
The packet header was not being included in the returned length.

source/net/protocol.cpp

index cee18367b7cb254abf220e33eaad1f76958679f0..95ba175932722a7e92c55ebdc603ff7494ce860e 100644 (file)
@@ -56,11 +56,11 @@ const Protocol::PacketDefBase &Protocol::get_packet_by_id(unsigned id) const
 size_t Protocol::dispatch(ReceiverBase &rcv, const char *buf, size_t size) const
 {
        PacketHeader header;
-       buf = header_def.deserialize(header, buf, buf+size);
+       const char *ptr = header_def.deserialize(header, buf, buf+size);
        if(header.length>size)
                throw bad_packet("truncated");
        const PacketDefBase &pdef = get_packet_by_id(header.type);
-       const char *ptr = pdef.dispatch(rcv, buf, buf+header.length);
+       ptr = pdef.dispatch(rcv, ptr, ptr+header.length);
        return ptr-buf;
 }