#include "tvbuff.h"
#include "strutil.h"
#include "emem.h"
+#include "proto.h" /* XXX - only used for DISSECTOR_ASSERT, probably a new header file? */
static const guint8*
ensure_contiguous_no_exception(tvbuff_t *tvb, gint offset, gint length,
tvbuff_t *tvb;
tvb = g_chunk_new(tvbuff_t, tvbuff_mem_chunk);
- g_assert(tvb);
tvb_init(tvb, type);
void
tvb_set_free_cb(tvbuff_t* tvb, tvbuff_free_cb_t func)
{
- g_assert(tvb->type == TVBUFF_REAL_DATA);
+ DISSECTOR_ASSERT(tvb->type == TVBUFF_REAL_DATA);
tvb->free_cb = func;
}
void
tvb_set_child_real_data_tvbuff(tvbuff_t* parent, tvbuff_t* child)
{
- g_assert(parent->initialized);
- g_assert(child->initialized);
- g_assert(child->type == TVBUFF_REAL_DATA);
+ DISSECTOR_ASSERT(parent->initialized);
+ DISSECTOR_ASSERT(child->initialized);
+ DISSECTOR_ASSERT(child->type == TVBUFF_REAL_DATA);
add_to_used_in_list(parent, child);
}
void
tvb_set_real_data(tvbuff_t* tvb, const guint8* data, guint length, gint reported_length)
{
- g_assert(tvb->type == TVBUFF_REAL_DATA);
- g_assert(!tvb->initialized);
+ DISSECTOR_ASSERT(tvb->type == TVBUFF_REAL_DATA);
+ DISSECTOR_ASSERT(!tvb->initialized);
if (reported_length < -1) {
THROW(ReportedBoundsError);
compute_offset_length(tvbuff_t *tvb, gint offset, gint length,
guint *offset_ptr, guint *length_ptr, int *exception)
{
- g_assert(offset_ptr);
- g_assert(length_ptr);
+ DISSECTOR_ASSERT(offset_ptr);
+ DISSECTOR_ASSERT(length_ptr);
/* Compute the offset */
if (offset >= 0) {
{
guint end_offset;
- g_assert(tvb);
- g_assert(tvb->initialized);
+ DISSECTOR_ASSERT(tvb);
+ DISSECTOR_ASSERT(tvb->initialized);
if (!compute_offset_length(tvb, offset, length, offset_ptr, length_ptr, exception)) {
return FALSE;
return FALSE;
}
- g_assert_not_reached();
+ DISSECTOR_ASSERT_NOT_REACHED();
}
/* Checks (+/-) offset and length and throws an exception if
int exception = 0;
if (!check_offset_length_no_exception(tvb, offset, length, offset_ptr, length_ptr, &exception)) {
- g_assert(exception > 0);
+ DISSECTOR_ASSERT(exception > 0);
THROW(exception);
}
return;
tvb_set_subset(tvbuff_t *tvb, tvbuff_t *backing,
gint backing_offset, gint backing_length, gint reported_length)
{
- g_assert(tvb->type == TVBUFF_SUBSET);
- g_assert(!tvb->initialized);
+ DISSECTOR_ASSERT(tvb->type == TVBUFF_SUBSET);
+ DISSECTOR_ASSERT(!tvb->initialized);
if (reported_length < -1) {
THROW(ReportedBoundsError);
{
tvb_comp_t *composite;
- g_assert(!tvb->initialized);
+ DISSECTOR_ASSERT(!tvb->initialized);
composite = &tvb->tvbuffs.composite;
composite->tvbs = g_slist_append( composite->tvbs, member );
add_to_used_in_list(member, tvb);
{
tvb_comp_t *composite;
- g_assert(!tvb->initialized);
+ DISSECTOR_ASSERT(!tvb->initialized);
composite = &tvb->tvbuffs.composite;
composite->tvbs = g_slist_prepend( composite->tvbs, member );
add_to_used_in_list(member, tvb);
tvb_comp_t *composite;
int i = 0;
- g_assert(!tvb->initialized);
- g_assert(tvb->length == 0);
+ DISSECTOR_ASSERT(!tvb->initialized);
+ DISSECTOR_ASSERT(tvb->length == 0);
composite = &tvb->tvbuffs.composite;
num_members = g_slist_length(composite->tvbs);
composite->end_offsets = g_new(guint, num_members);
for (slist = composite->tvbs; slist != NULL; slist = slist->next) {
- g_assert((guint) i < num_members);
+ DISSECTOR_ASSERT((guint) i < num_members);
member_tvb = slist->data;
composite->start_offsets[i] = tvb->length;
tvb->length += member_tvb->length;
guint
tvb_length(tvbuff_t* tvb)
{
- g_assert(tvb->initialized);
+ DISSECTOR_ASSERT(tvb->initialized);
return tvb->length;
}
{
guint abs_offset, abs_length;
- g_assert(tvb->initialized);
+ DISSECTOR_ASSERT(tvb->initialized);
if (compute_offset_length(tvb, offset, -1, &abs_offset, &abs_length, NULL)) {
return abs_length;
guint abs_offset, abs_length;
int exception;
- g_assert(tvb->initialized);
+ DISSECTOR_ASSERT(tvb->initialized);
if (!compute_offset_length(tvb, offset, -1, &abs_offset, &abs_length, &exception)) {
THROW(exception);
{
guint abs_offset, abs_length;
- g_assert(tvb->initialized);
+ DISSECTOR_ASSERT(tvb->initialized);
if (!compute_offset_length(tvb, offset, length, &abs_offset, &abs_length, NULL))
return FALSE;
{
guint abs_offset, abs_length;
- g_assert(tvb->initialized);
+ DISSECTOR_ASSERT(tvb->initialized);
/*
* -1 doesn't mean "until end of buffer", as that's pointless
{
guint abs_offset, abs_length;
- g_assert(tvb->initialized);
+ DISSECTOR_ASSERT(tvb->initialized);
if (!compute_offset_length(tvb, offset, -1, &abs_offset, &abs_length, NULL))
return FALSE;
guint
tvb_reported_length(tvbuff_t* tvb)
{
- g_assert(tvb->initialized);
+ DISSECTOR_ASSERT(tvb->initialized);
return tvb->reported_length;
}
{
guint abs_offset, abs_length;
- g_assert(tvb->initialized);
+ DISSECTOR_ASSERT(tvb->initialized);
if (compute_offset_length(tvb, offset, -1, &abs_offset, &abs_length, NULL)) {
if (tvb->reported_length >= abs_offset)
void
tvb_set_reported_length(tvbuff_t* tvb, guint reported_length)
{
- g_assert(tvb->initialized);
+ DISSECTOR_ASSERT(tvb->initialized);
if (reported_length > tvb->reported_length)
THROW(ReportedBoundsError);
return first_real_data_ptr(member);
}
- g_assert_not_reached();
+ DISSECTOR_ASSERT_NOT_REACHED();
return NULL;
}
return offset_from_real_beginning(member, counter);
}
- g_assert_not_reached();
+ DISSECTOR_ASSERT_NOT_REACHED();
return 0;
}
guint member_offset, member_length;
GSList *slist;
- g_assert(tvb->type == TVBUFF_COMPOSITE);
+ DISSECTOR_ASSERT(tvb->type == TVBUFF_COMPOSITE);
/* Maybe the range specified by offset/length
* is contiguous inside one of the member tvbuffs */
break;
}
}
- g_assert(member_tvb);
+ DISSECTOR_ASSERT(member_tvb);
if (check_offset_length_no_exception(member_tvb, abs_offset - composite->start_offsets[i],
abs_length, &member_offset, &member_length, NULL)) {
/*
* The range is, in fact, contiguous within member_tvb.
*/
- g_assert(!tvb->real_data);
+ DISSECTOR_ASSERT(!tvb->real_data);
return ensure_contiguous_no_exception(member_tvb, member_offset, member_length, NULL);
}
else {
return tvb->real_data + abs_offset;
}
- g_assert_not_reached();
+ DISSECTOR_ASSERT_NOT_REACHED();
return NULL;
}
else {
switch(tvb->type) {
case TVBUFF_REAL_DATA:
- g_assert_not_reached();
+ DISSECTOR_ASSERT_NOT_REACHED();
case TVBUFF_SUBSET:
return ensure_contiguous_no_exception(tvb->tvbuffs.subset.tvb,
abs_offset - tvb->tvbuffs.subset.offset,
}
}
- g_assert_not_reached();
+ DISSECTOR_ASSERT_NOT_REACHED();
return NULL;
}
p = ensure_contiguous_no_exception(tvb, offset, length, &exception);
if (p == NULL) {
- g_assert(exception > 0);
+ DISSECTOR_ASSERT(exception > 0);
THROW(exception);
}
return p;
gboolean retval;
GSList *slist;
- g_assert(tvb->type == TVBUFF_COMPOSITE);
+ DISSECTOR_ASSERT(tvb->type == TVBUFF_COMPOSITE);
/* Maybe the range specified by offset/length
* is contiguous inside one of the member tvbuffs */
break;
}
}
- g_assert(member_tvb);
+ DISSECTOR_ASSERT(member_tvb);
if (check_offset_length_no_exception(member_tvb, abs_offset - composite->start_offsets[i],
abs_length, &member_offset, &member_length, NULL)) {
- g_assert(!tvb->real_data);
+ DISSECTOR_ASSERT(!tvb->real_data);
return tvb_memcpy(member_tvb, target, member_offset, member_length);
}
else {
*/
retval = compute_offset_length(member_tvb, abs_offset - composite->start_offsets[i], -1,
&member_offset, &member_length, NULL);
- g_assert(retval);
+ DISSECTOR_ASSERT(retval);
tvb_memcpy(member_tvb, target, member_offset, member_length);
abs_offset += member_length;
return target;
}
- g_assert_not_reached();
+ DISSECTOR_ASSERT_NOT_REACHED();
return NULL;
}
{
guint abs_offset, abs_length;
- g_assert(length >= -1);
+ DISSECTOR_ASSERT(length >= -1);
check_offset_length(tvb, offset, length, &abs_offset, &abs_length);
if (tvb->real_data) {
switch(tvb->type) {
case TVBUFF_REAL_DATA:
- g_assert_not_reached();
+ DISSECTOR_ASSERT_NOT_REACHED();
case TVBUFF_SUBSET:
return tvb_memcpy(tvb->tvbuffs.subset.tvb, target,
return composite_memcpy(tvb, target, offset, length);
}
- g_assert_not_reached();
+ DISSECTOR_ASSERT_NOT_REACHED();
return NULL;
}
switch(tvb->type) {
case TVBUFF_REAL_DATA:
- g_assert_not_reached();
+ DISSECTOR_ASSERT_NOT_REACHED();
case TVBUFF_SUBSET:
return tvb_find_guint8(tvb->tvbuffs.subset.tvb,
limit, needle);
case TVBUFF_COMPOSITE:
- g_assert_not_reached();
+ DISSECTOR_ASSERT_NOT_REACHED();
/* XXX - return composite_find_guint8(tvb, offset, limit, needle); */
}
- g_assert_not_reached();
+ DISSECTOR_ASSERT_NOT_REACHED();
return -1;
}
switch(tvb->type) {
case TVBUFF_REAL_DATA:
- g_assert_not_reached();
+ DISSECTOR_ASSERT_NOT_REACHED();
case TVBUFF_SUBSET:
return tvb_pbrk_guint8(tvb->tvbuffs.subset.tvb,
limit, needles);
case TVBUFF_COMPOSITE:
- g_assert_not_reached();
+ DISSECTOR_ASSERT_NOT_REACHED();
/* XXX - return composite_pbrk_guint8(tvb, offset, limit, needle); */
}
- g_assert_not_reached();
+ DISSECTOR_ASSERT_NOT_REACHED();
return -1;
}
check_offset_length(tvb, offset, 0, &abs_offset, &junk_length);
/* There must at least be room for the terminating NUL. */
- g_assert(bufsize != 0);
+ DISSECTOR_ASSERT(bufsize != 0);
/* If there's no room for anything else, just return the NUL. */
if (bufsize == 1) {
/* This should not happen because check_offset_length() would
* have already thrown an exception if 'offset' were out-of-bounds.
*/
- g_assert(len != -1);
+ DISSECTOR_ASSERT(len != -1);
/*
* If we've been passed a negative number, bufsize will
* be huge.
*/
- g_assert(bufsize <= G_MAXINT);
+ DISSECTOR_ASSERT(bufsize <= G_MAXINT);
if ((guint)len < bufsize) {
limit = len;