Hi,
I should've first commit this changes and later move composite stuff to another file, but I haven't thought.
Sorry. Anyway, attaching diff with important changes.
If anyone has some time to do review it'd be great.
Thanks,
Kuba.
--- 9d519b5659aa8c0c4aa984bc6169909eb31be7d6_2.c 2013-07-31 22:50:46.144101741 +0200
+++ 9d519b5659aa8c0c4aa984bc6169909eb31be7d6_1.c 2013-07-31 22:50:36.800818660 +0200
@@ -32,11 +32,10 @@
guint i, num_members;
tvb_comp_t *composite;
tvbuff_t *member_tvb = NULL;
- guint member_offset, member_length;
+ guint member_offset;
GSList *slist;
- int exception;
- DISSECTOR_ASSERT(tvb->ops == get_tvb_composite_ops());
+ /* DISSECTOR_ASSERT(tvb->ops == &tvb_composite_ops); */
/* Maybe the range specified by offset/length
* is contiguous inside one of the member tvbuffs */
@@ -52,16 +51,14 @@
}
DISSECTOR_ASSERT(member_tvb);
- exception = check_offset_length_no_exception(member_tvb,
- abs_offset - composite->start_offsets[i],
- abs_length, &member_offset, &member_length);
+ member_offset = abs_offset - composite->start_offsets[i];
- if (!exception) {
+ if (tvb_bytes_exist(member_tvb, member_offset, abs_length)) {
/*
* The range is, in fact, contiguous within member_tvb.
*/
DISSECTOR_ASSERT(!tvb->real_data);
- return ensure_contiguous_no_exception(member_tvb, member_offset, member_length, NULL);
+ return tvb_get_ptr(member_tvb, member_offset, abs_length);
}
else {
tvb->real_data = (guint8 *)tvb_memdup(tvb, 0, -1);
@@ -72,7 +69,7 @@
}
static void *
-composite_memcpy(tvbuff_t *tvb, void* _target, guint abs_offset, size_t abs_length)
+composite_memcpy(tvbuff_t *tvb, void* _target, guint abs_offset, guint abs_length)
{
struct tvb_composite *composite_tvb = (struct tvb_composite *) tvb;
guint8 *target = (guint8 *) _target;
@@ -81,10 +78,9 @@
tvb_comp_t *composite;
tvbuff_t *member_tvb = NULL;
guint member_offset, member_length;
- int exception;
GSList *slist;
- DISSECTOR_ASSERT(tvb->ops == get_tvb_composite_ops());
+ /* DISSECTOR_ASSERT(tvb->ops == &tvb_composite_ops); */
/* Maybe the range specified by offset/length
* is contiguous inside one of the member tvbuffs */
@@ -100,12 +96,11 @@
}
DISSECTOR_ASSERT(member_tvb);
- exception = check_offset_length_no_exception(member_tvb, abs_offset - composite->start_offsets[i],
- (gint) abs_length, &member_offset, &member_length);
+ member_offset = abs_offset - composite->start_offsets[i];
- if (!exception) {
+ if (tvb_bytes_exist(member_tvb, member_offset, abs_length)) {
DISSECTOR_ASSERT(!tvb->real_data);
- return tvb_memcpy(member_tvb, target, member_offset, member_length);
+ return tvb_memcpy(member_tvb, target, member_offset, abs_length);
}
else {
/* The requested data is non-contiguous inside
@@ -113,12 +108,10 @@
* then iterate across the other member tvb's, copying their portions
* until we have copied all data.
*/
- exception = compute_offset_and_remaining(member_tvb, abs_offset - composite->start_offsets[i],
- &member_offset, &member_length);
- DISSECTOR_ASSERT(!exception);
+ member_length = tvb_length_remaining(member_tvb, member_offset);
/* composite_memcpy() can't handle a member_length of zero. */
- DISSECTOR_ASSERT(member_length);
+ DISSECTOR_ASSERT(member_length > 0);
tvb_memcpy(member_tvb, target, member_offset, member_length);
abs_offset += member_length;