aboutsummaryrefslogtreecommitdiffstats
path: root/epan/tvbuff.c
diff options
context:
space:
mode:
authorLuis Ontanon <luis.ontanon@gmail.com>2005-07-26 18:32:12 +0000
committerLuis Ontanon <luis.ontanon@gmail.com>2005-07-26 18:32:12 +0000
commitc5688891a15aad52c20feed8cf401e0e51f5cbf7 (patch)
tree340a32503d93c49eb5e3db35d7a7caa9f99afa07 /epan/tvbuff.c
parentda94bcb0e7d0fcd2dca65cfc39ccf685f0cf01cd (diff)
new functions:
ep_tvb_memdup() ep_alloc0() ep_strsplit() add all of the ep_ allocators to libethereal.def svn path=/trunk/; revision=15100
Diffstat (limited to 'epan/tvbuff.c')
-rw-r--r--epan/tvbuff.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/epan/tvbuff.c b/epan/tvbuff.c
index b63f568f69..ab6bd7896f 100644
--- a/epan/tvbuff.c
+++ b/epan/tvbuff.c
@@ -1002,13 +1002,41 @@ tvb_memdup(tvbuff_t *tvb, gint offset, gint length)
{
guint abs_offset, abs_length;
guint8 *duped;
-
+
check_offset_length(tvb, offset, length, &abs_offset, &abs_length);
-
+
duped = g_malloc(abs_length);
return tvb_memcpy(tvb, duped, abs_offset, abs_length);
}
+/*
+ * XXX - this doesn't treat a length of -1 as an error.
+ * If it did, this could replace some code that calls
+ * "tvb_ensure_bytes_exist()" and then allocates a buffer and copies
+ * data to it.
+ *
+ * "composite_ensure_contiguous_no_exception()" depends on -1 not being
+ * an error; does anything else depend on this routine treating -1 as
+ * meaning "to the end of the buffer"?
+ *
+ * This function allocates memory from a buffer with packet lifetime.
+ * You do not have to free this buffer, it will be automatically freed
+ * when ethereal starts decoding the next packet.
+ * Do not use this function if you want the allocated memory to be persistent
+ * after the current packet has been dissected.
+ */
+guint8*
+ep_tvb_memdup(tvbuff_t *tvb, gint offset, gint length)
+{
+ guint abs_offset, abs_length;
+ guint8 *duped;
+
+ check_offset_length(tvb, offset, length, &abs_offset, &abs_length);
+
+ duped = ep_alloc(abs_length);
+ return tvb_memcpy(tvb, duped, abs_offset, abs_length);
+}
+
const guint8*