WSDG: Update docbook info
[metze/wireshark/wip.git] / epan / tvbuff_composite.c
index 62ca4fdefea213b401125e96ac7cd9e80a55ab71..5832477f816211d8d2e6a8243ee57c8d7d08ec25 100644 (file)
@@ -1,6 +1,4 @@
 /* tvbuff_composite.c
- *
- * $Id$
  *
  * Copyright (c) 2000 by Gilbert Ramirez <gram@alumni.rice.edu>
  *
@@ -8,25 +6,11 @@
  * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
 #include "config.h"
 
-#include <epan/emem.h>
-
 #include "tvbuff.h"
 #include "tvbuff-int.h"
 #include "proto.h"     /* XXX - only used for DISSECTOR_ASSERT, probably a new header file? */
@@ -116,7 +100,10 @@ composite_get_ptr(tvbuff_t *tvb, guint abs_offset, guint abs_length)
                return tvb_get_ptr(member_tvb, member_offset, abs_length);
        }
        else {
-               tvb->real_data = (guint8 *)tvb_memdup(tvb, 0, -1);
+               /* Use a temporary variable as tvb_memcpy is also checking tvb->real_data pointer */
+               void *real_data = g_malloc(tvb->length);
+               tvb_memcpy(tvb, real_data, 0, tvb->length);
+               tvb->real_data = (const guint8 *)real_data;
                return tvb->real_data + abs_offset;
        }
 
@@ -168,7 +155,7 @@ composite_memcpy(tvbuff_t *tvb, void* _target, guint abs_offset, guint abs_lengt
                 * then iterate across the other member tvb's, copying their portions
                 * until we have copied all data.
                 */
-               member_length = tvb_length_remaining(member_tvb, member_offset);
+               member_length = tvb_captured_length_remaining(member_tvb, member_offset);
 
                /* composite_memcpy() can't handle a member_length of zero. */
                DISSECTOR_ASSERT(member_length > 0);
@@ -294,6 +281,23 @@ tvb_composite_finalize(tvbuff_t *tvb)
                composite->end_offsets[i] = tvb->length - 1;
                i++;
        }
+
+       DISSECTOR_ASSERT(composite->tvbs);
+
        tvb_add_to_chain((tvbuff_t *)composite->tvbs->data, tvb); /* chain composite tvb to first member */
        tvb->initialized = TRUE;
+       tvb->ds_tvb = tvb;
 }
+
+/*
+ * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 8
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * End:
+ *
+ * vi: set shiftwidth=8 tabstop=8 noexpandtab:
+ * :indentSize=8:tabSize=8:noTabs=false:
+ */