diff options
author | Guy Harris <guy@alum.mit.edu> | 2004-02-12 20:58:01 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2004-02-12 20:58:01 +0000 |
commit | ea3e87cb460ceffbace60a4ec8b3097fef73dd91 (patch) | |
tree | 062b5aaae90149f8870b997a54efe70088a561cf /packet-slsk.c | |
parent | f689434393a752fcdfebce91ded1125eead7d3fa (diff) |
From Kendy Kutzner: don't use variable-length arrays, not all C
compilers support them.
Also, use "tvb_memdup()" to make a copy of the compressed data - it's
faster, and also checks to make sure the data is actually there (it
throws an exception before allocating anything).
svn path=/trunk/; revision=10048
Diffstat (limited to 'packet-slsk.c')
-rw-r--r-- | packet-slsk.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/packet-slsk.c b/packet-slsk.c index 2d16460907..3079639cd1 100644 --- a/packet-slsk.c +++ b/packet-slsk.c @@ -9,7 +9,7 @@ * http://cvs.sourceforge.net/viewcvs.py/soleseek/SoleSeek/doc/protocol.html?rev=HEAD * Updated for SoulSeek client version 151 * - * $Id: packet-slsk.c,v 1.1 2004/02/11 20:23:19 jmayer Exp $ + * $Id: packet-slsk.c,v 1.2 2004/02/12 20:58:01 guy Exp $ * * * Ethereal - Network traffic analyzer @@ -304,19 +304,31 @@ static tvbuff_t* uncompress_packet(tvbuff_t *tvb, int offset, int comprlen){ * or NULL if uncompression failed */ - char compr[comprlen]; - int i = 0; + int err; long uncomprlen = (comprlen*10); - char uncompr[uncomprlen]; - int err = 0; + guint8 * compr; + guint8 * uncompr; tvbuff_t *uncompr_tvb; - while (i < comprlen) { compr[i] = tvb_get_guint8(tvb, offset+i); i++;} + compr = tvb_memdup(tvb, offset, comprlen); + if (!compr) + return NULL; + + uncompr = g_malloc(uncomprlen); + if (!uncompr){ + g_free(compr); + return NULL; + } err = uncompress((Bytef *)uncompr, &uncomprlen, (Bytef *)compr, comprlen); - if (err != 0) return NULL; + g_free(compr); + if (err != 0) { + g_free(uncompr); + return NULL; + } uncompr_tvb = tvb_new_real_data((guint8*) uncompr, uncomprlen, uncomprlen); + g_free(uncompr); return uncompr_tvb; } #else |