From 324986694a995115f8d43636d108efe5b400087c Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Wed, 26 Oct 2011 10:26:56 +0200 Subject: [PATCH] decode: improve and fix comments. --- src/decode.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/decode.c b/src/decode.c index faccc03f76..b35ebe7db8 100644 --- a/src/decode.c +++ b/src/decode.c @@ -268,6 +268,12 @@ DecodeThreadVars *DecodeThreadVarsAlloc() { /** * \brief Copy data to Packet payload at given offset * + * This function copies data/payload to a Packet. It uses the + * space allocated at Packet creation (pointed by Packet::pkt) + * or allocate some memory (pointed by Packet::ext_pkt) if the + * data size is to big to fit in initial space (of size + * default_packet_size). + * * \param Pointer to the Packet to modify * \param Offset of the copy relatively to payload of Packet * \param Pointer to the data to copy @@ -280,13 +286,13 @@ inline int PacketCopyDataOffset(Packet *p, int offset, uint8_t *data, int datale return -1; } + /* Do we have already an packet with allocated data */ if (! p->ext_pkt) { if (offset + datalen <= default_packet_size) { + /* data will fit in memory allocated with packet */ memcpy(p->pkt + offset, data, datalen); } else { - /* here we need a dynamic allocation. This case should rarely - * occur as there is a high probability the first frag has - * reveal the packet size*/ + /* here we need a dynamic allocation */ p->ext_pkt = SCMalloc(MAX_PAYLOAD_SIZE); if (p->ext_pkt == NULL) { SET_PKT_LEN(p, 0);