summaryrefslogtreecommitdiff
path: root/epan/tvbuff.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2013-02-24 21:45:09 +0000
committerGuy Harris <guy@alum.mit.edu>2013-02-24 21:45:09 +0000
commitd02eea90a2549414e7de485749367d35d835f0aa (patch)
treeb938fed4100a4355266dee93cabe0d34ddf1a3c8 /epan/tvbuff.c
parent14b01f991c29e8b2a073bb71c34cc18210475b24 (diff)
downloadwireshark-d02eea90a2549414e7de485749367d35d835f0aa.tar.gz
compute_offset_length(), check_offset_length_no_exception(), and
check_offset_length() are always passed the captured length and reported length of a tvbuff; just pass a pointer to the tvbuff, instead. Eliminate some extra blank lines. svn path=/trunk/; revision=47868
Diffstat (limited to 'epan/tvbuff.c')
-rw-r--r--epan/tvbuff.c72
1 files changed, 35 insertions, 37 deletions
diff --git a/epan/tvbuff.c b/epan/tvbuff.c
index 64b39d61e8..d6823080ca 100644
--- a/epan/tvbuff.c
+++ b/epan/tvbuff.c
@@ -104,7 +104,6 @@ tvb_init(tvbuff_t *tvb, const tvbuff_type type)
}
}
-
static tvbuff_t *
tvb_new(const tvbuff_type type)
{
@@ -262,7 +261,7 @@ tvb_new_child_real_data(tvbuff_t *parent, const guint8* data, const guint length
* that gets an exception, so the error is reported as an error in that
* protocol rather than the containing protocol. */
static gboolean
-compute_offset_length(const guint tvb_length_val, const guint tvb_reported_length_val,
+compute_offset_length(const tvbuff_t *tvb,
const gint offset, const gint length_val,
guint *offset_ptr, guint *length_ptr, int *exception)
{
@@ -272,13 +271,13 @@ compute_offset_length(const guint tvb_length_val, const guint tvb_reported_lengt
/* Compute the offset */
if (offset >= 0) {
/* Positive offset - relative to the beginning of the packet. */
- if ((guint) offset > tvb_reported_length_val) {
+ if ((guint) offset > tvb->reported_length) {
if (exception) {
*exception = ReportedBoundsError;
}
return FALSE;
}
- else if ((guint) offset > tvb_length_val) {
+ else if ((guint) offset > tvb->length) {
if (exception) {
*exception = BoundsError;
}
@@ -290,20 +289,20 @@ compute_offset_length(const guint tvb_length_val, const guint tvb_reported_lengt
}
else {
/* Negative offset - relative to the end of the packet. */
- if ((guint) -offset > tvb_reported_length_val) {
+ if ((guint) -offset > tvb->reported_length) {
if (exception) {
*exception = ReportedBoundsError;
}
return FALSE;
}
- else if ((guint) -offset > tvb_length_val) {
+ else if ((guint) -offset > tvb->length) {
if (exception) {
*exception = BoundsError;
}
return FALSE;
}
else {
- *offset_ptr = tvb_length_val + offset;
+ *offset_ptr = tvb->length + offset;
}
}
@@ -316,7 +315,7 @@ compute_offset_length(const guint tvb_length_val, const guint tvb_reported_lengt
return FALSE;
}
else if (length_val == -1) {
- *length_ptr = tvb_length_val - *offset_ptr;
+ *length_ptr = tvb->length - *offset_ptr;
}
else {
*length_ptr = length_val;
@@ -325,15 +324,14 @@ compute_offset_length(const guint tvb_length_val, const guint tvb_reported_lengt
return TRUE;
}
-
static gboolean
-check_offset_length_no_exception(const guint tvb_length_val, const guint tvb_reported_length_val,
+check_offset_length_no_exception(const tvbuff_t *tvb,
const gint offset, gint const length_val,
guint *offset_ptr, guint *length_ptr, int *exception)
{
guint end_offset;
- if (!compute_offset_length(tvb_length_val, tvb_reported_length_val,
+ if (!compute_offset_length(tvb,
offset, length_val, offset_ptr, length_ptr, exception)) {
return FALSE;
}
@@ -358,10 +356,10 @@ check_offset_length_no_exception(const guint tvb_length_val, const guint tvb_rep
* If not, return TRUE; otherwise, return FALSE and, if "exception"
* is non-null, return the appropriate exception through it.
*/
- if (end_offset <= tvb_length_val) {
+ if (end_offset <= tvb->length) {
return TRUE;
}
- else if (end_offset <= tvb_reported_length_val) {
+ else if (end_offset <= tvb->reported_length) {
if (exception) {
*exception = BoundsError;
}
@@ -379,13 +377,13 @@ check_offset_length_no_exception(const guint tvb_length_val, const guint tvb_rep
* either is out of bounds. Sets integer ptrs to the new offset
* and length. */
static void
-check_offset_length(const guint tvb_length_val, const guint tvb_reported_length_val,
+check_offset_length(const tvbuff_t *tvb,
const gint offset, gint const length_val,
guint *offset_ptr, guint *length_ptr)
{
int exception = 0;
- if (!check_offset_length_no_exception(tvb_length_val, tvb_reported_length_val,
+ if (!check_offset_length_no_exception(tvb,
offset, length_val, offset_ptr, length_ptr, &exception)) {
DISSECTOR_ASSERT(exception > 0);
THROW(exception);
@@ -433,7 +431,7 @@ tvb_new_subset(tvbuff_t *backing, const gint backing_offset, const gint backing_
THROW_ON(reported_length < -1, ReportedBoundsError);
- check_offset_length(backing->length, backing->reported_length, backing_offset, backing_length,
+ check_offset_length(backing, backing_offset, backing_length,
&subset_tvb_offset,
&subset_tvb_length);
@@ -469,7 +467,7 @@ tvb_new_subset_length(tvbuff_t *backing, const gint backing_offset, const gint b
if (captured_length > backing_length)
captured_length = backing_length;
- check_offset_length(backing->length, backing->reported_length, backing_offset, captured_length,
+ check_offset_length(backing, backing_offset, captured_length,
&subset_tvb_offset,
&subset_tvb_length);
@@ -492,7 +490,7 @@ tvb_new_subset_remaining(tvbuff_t *backing, const gint backing_offset)
guint subset_tvb_offset;
guint subset_tvb_length;
- check_offset_length(backing->length, backing->reported_length, backing_offset, -1 /* backing_length */,
+ check_offset_length(backing, backing_offset, -1 /* backing_length */,
&subset_tvb_offset,
&subset_tvb_length);
@@ -680,7 +678,7 @@ tvb_length_remaining(const tvbuff_t *tvb, const gint offset)
DISSECTOR_ASSERT(tvb && tvb->initialized);
- if (compute_offset_length(tvb->length, tvb->reported_length, offset, -1, &abs_offset, &abs_length, NULL)) {
+ if (compute_offset_length(tvb, offset, -1, &abs_offset, &abs_length, NULL)) {
return abs_length;
}
else {
@@ -696,7 +694,7 @@ tvb_ensure_length_remaining(const tvbuff_t *tvb, const gint offset)
DISSECTOR_ASSERT(tvb && tvb->initialized);
- if (!compute_offset_length(tvb->length, tvb->reported_length, offset, -1, &abs_offset, &abs_length, &exception)) {
+ if (!compute_offset_length(tvb, offset, -1, &abs_offset, &abs_length, &exception)) {
THROW(exception);
}
if (abs_length == 0) {
@@ -725,7 +723,7 @@ tvb_bytes_exist(const tvbuff_t *tvb, const gint offset, const gint length)
DISSECTOR_ASSERT(tvb && tvb->initialized);
- if (!compute_offset_length(tvb->length, tvb->reported_length, offset, length, &abs_offset, &abs_length, NULL))
+ if (!compute_offset_length(tvb, offset, length, &abs_offset, &abs_length, NULL))
return FALSE;
if (abs_offset + abs_length <= tvb->length) {
@@ -758,7 +756,7 @@ tvb_ensure_bytes_exist(const tvbuff_t *tvb, const gint offset, const gint length
if (length < 0) {
THROW(ReportedBoundsError);
}
- check_offset_length(tvb->length, tvb->reported_length, offset, length, &abs_offset, &abs_length);
+ check_offset_length(tvb, offset, length, &abs_offset, &abs_length);
}
gboolean
@@ -767,7 +765,7 @@ tvb_offset_exists(const tvbuff_t *tvb, const gint offset)
guint abs_offset, abs_length;
DISSECTOR_ASSERT(tvb && tvb->initialized);
- if (!compute_offset_length(tvb->length, tvb->reported_length, offset, -1, &abs_offset, &abs_length, NULL))
+ if (!compute_offset_length(tvb, offset, -1, &abs_offset, &abs_length, NULL))
return FALSE;
if (abs_offset < tvb->length) {
@@ -793,7 +791,7 @@ tvb_reported_length_remaining(const tvbuff_t *tvb, const gint offset)
DISSECTOR_ASSERT(tvb && tvb->initialized);
- if (compute_offset_length(tvb->length, tvb->reported_length, offset, -1, &abs_offset, &abs_length, NULL)) {
+ if (compute_offset_length(tvb, offset, -1, &abs_offset, &abs_length, NULL)) {
if (tvb->reported_length >= abs_offset)
return tvb->reported_length - abs_offset;
else
@@ -896,7 +894,7 @@ composite_ensure_contiguous_no_exception(tvbuff_t *tvb, const guint abs_offset,
}
DISSECTOR_ASSERT(member_tvb);
- if (check_offset_length_no_exception(member_tvb->length, member_tvb->reported_length,
+ if (check_offset_length_no_exception(member_tvb,
abs_offset - composite->start_offsets[i],
abs_length, &member_offset, &member_length, NULL)) {
@@ -919,7 +917,7 @@ ensure_contiguous_no_exception(tvbuff_t *tvb, const gint offset, const gint leng
{
guint abs_offset, abs_length;
- if (!check_offset_length_no_exception(tvb->length, tvb->reported_length, offset, length,
+ if (!check_offset_length_no_exception(tvb, offset, length,
&abs_offset, &abs_length, exception)) {
return NULL;
}
@@ -1043,7 +1041,7 @@ composite_memcpy(tvbuff_t *tvb, guint8* target, guint abs_offset, size_t abs_len
}
DISSECTOR_ASSERT(member_tvb);
- if (check_offset_length_no_exception(member_tvb->length, member_tvb->reported_length, abs_offset - composite->start_offsets[i],
+ if (check_offset_length_no_exception(member_tvb, abs_offset - composite->start_offsets[i],
(gint) abs_length, &member_offset, &member_length, NULL)) {
DISSECTOR_ASSERT(!tvb->real_data);
@@ -1055,7 +1053,7 @@ composite_memcpy(tvbuff_t *tvb, guint8* target, guint abs_offset, size_t abs_len
* then iterate across the other member tvb's, copying their portions
* until we have copied all data.
*/
- retval = compute_offset_length(member_tvb->length, member_tvb->reported_length, abs_offset - composite->start_offsets[i], -1,
+ retval = compute_offset_length(member_tvb, abs_offset - composite->start_offsets[i], -1,
&member_offset, &member_length, NULL);
DISSECTOR_ASSERT(retval);
@@ -1096,7 +1094,7 @@ tvb_memcpy(tvbuff_t *tvb, void *target, const gint offset, size_t length)
* instead, we check for a length <= 2^31-1.
*/
DISSECTOR_ASSERT(length <= 0x7FFFFFFF);
- check_offset_length(tvb->length, tvb->reported_length, offset, (gint) length, &abs_offset, &abs_length);
+ check_offset_length(tvb, offset, (gint) length, &abs_offset, &abs_length);
if (tvb->real_data) {
return memcpy(target, tvb->real_data + abs_offset, abs_length);
@@ -1138,7 +1136,7 @@ tvb_memdup(tvbuff_t *tvb, const gint offset, size_t length)
DISSECTOR_ASSERT(tvb && tvb->initialized);
- check_offset_length(tvb->length, tvb->reported_length, offset, (gint) length, &abs_offset, &abs_length);
+ check_offset_length(tvb, offset, (gint) length, &abs_offset, &abs_length);
duped = g_malloc(abs_length);
return tvb_memcpy(tvb, duped, abs_offset, abs_length);
@@ -1168,7 +1166,7 @@ ep_tvb_memdup(tvbuff_t *tvb, const gint offset, size_t length)
DISSECTOR_ASSERT(tvb && tvb->initialized);
- check_offset_length(tvb->length, tvb->reported_length, offset, (gint) length, &abs_offset, &abs_length);
+ check_offset_length(tvb, offset, (gint) length, &abs_offset, &abs_length);
duped = ep_alloc(abs_length);
return tvb_memcpy(tvb, duped, abs_offset, abs_length);
@@ -1886,7 +1884,7 @@ tvb_find_guint8(tvbuff_t *tvb, const gint offset, const gint maxlength, const gu
DISSECTOR_ASSERT(tvb && tvb->initialized);
- check_offset_length(tvb->length, tvb->reported_length, offset, 0, &abs_offset, &junk_length);
+ check_offset_length(tvb, offset, 0, &abs_offset, &junk_length);
/* Only search to end of tvbuff, w/o throwing exception. */
tvbufflen = tvb_length_remaining(tvb, abs_offset);
@@ -1951,7 +1949,7 @@ tvb_pbrk_guint8(tvbuff_t *tvb, const gint offset, const gint maxlength, const gu
DISSECTOR_ASSERT(tvb && tvb->initialized);
- check_offset_length(tvb->length, tvb->reported_length, offset, 0, &abs_offset, &junk_length);
+ check_offset_length(tvb, offset, 0, &abs_offset, &junk_length);
/* Only search to end of tvbuff, w/o throwing exception. */
tvbufflen = tvb_length_remaining(tvb, abs_offset);
@@ -2012,7 +2010,7 @@ tvb_strsize(tvbuff_t *tvb, const gint offset)
DISSECTOR_ASSERT(tvb && tvb->initialized);
- check_offset_length(tvb->length, tvb->reported_length, offset, 0, &abs_offset, &junk_length);
+ check_offset_length(tvb, offset, 0, &abs_offset, &junk_length);
nul_offset = tvb_find_guint8(tvb, abs_offset, -1, 0);
if (nul_offset == -1) {
/*
@@ -2065,7 +2063,7 @@ tvb_strnlen(tvbuff_t *tvb, const gint offset, const guint maxlength)
DISSECTOR_ASSERT(tvb && tvb->initialized);
- check_offset_length(tvb->length, tvb->reported_length, offset, 0, &abs_offset, &junk_length);
+ check_offset_length(tvb, offset, 0, &abs_offset, &junk_length);
result_offset = tvb_find_guint8(tvb, abs_offset, maxlength, 0);
@@ -2802,7 +2800,7 @@ _tvb_get_nstringz(tvbuff_t *tvb, const gint offset, const guint bufsize, guint8*
gint limit, len;
gboolean decreased_max = FALSE;
- check_offset_length(tvb->length, tvb->reported_length, offset, 0, &abs_offset, &junk_length);
+ check_offset_length(tvb, offset, 0, &abs_offset, &junk_length);
/* There must at least be room for the terminating NUL. */
DISSECTOR_ASSERT(bufsize != 0);
@@ -3329,7 +3327,7 @@ tvb_find_tvb(tvbuff_t *haystack_tvb, tvbuff_t *needle_tvb, const gint haystack_o
haystack_data = ensure_contiguous(haystack_tvb, 0, -1);
needle_data = ensure_contiguous(needle_tvb, 0, -1);
- check_offset_length(haystack_tvb->length, haystack_tvb->reported_length, haystack_offset, -1,
+ check_offset_length(haystack_tvb, haystack_offset, -1,
&haystack_abs_offset, &haystack_abs_length);
location = epan_memmem(haystack_data + haystack_abs_offset, haystack_abs_length,