extract common logic of proto_item_set_len/proto_item_set_end

Change-Id: I55f9303624471d09b446c10939e5c22bf8e21511
Reviewed-on: https://code.wireshark.org/review/18894
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
Dmitry Lazurkin 2016-11-20 16:39:31 +03:00 committed by Michael Mann
parent 0f36cf62b7
commit 03a2539b22
1 changed files with 17 additions and 18 deletions

View File

@ -5447,6 +5447,21 @@ proto_item_prepend_text(proto_item *pi, const char *format, ...)
}
}
static void
finfo_set_len(field_info *fi, const gint length)
{
DISSECTOR_ASSERT(length >= 0);
fi->length = length;
/*
* You cannot just make the "len" field of a GByteArray
* larger, if there's no data to back that length;
* you can only make it smaller.
*/
if (fi->value.ftype->ftype == FT_BYTES && length <= (gint)fi->value.value.bytes->len)
fi->value.value.bytes->len = length;
}
void
proto_item_set_len(proto_item *pi, const gint length)
{
@ -5458,16 +5473,7 @@ proto_item_set_len(proto_item *pi, const gint length)
if (fi == NULL)
return;
DISSECTOR_ASSERT(length >= 0);
fi->length = length;
/*
* You cannot just make the "len" field of a GByteArray
* larger, if there's no data to back that length;
* you can only make it smaller.
*/
if (fi->value.ftype->ftype == FT_BYTES && length <= (gint)fi->value.value.bytes->len)
fi->value.value.bytes->len = length;
finfo_set_len(fi, length);
}
/*
@ -5492,15 +5498,8 @@ proto_item_set_end(proto_item *pi, tvbuff_t *tvb, gint end)
end += tvb_raw_offset(tvb);
DISSECTOR_ASSERT(end >= fi->start);
length = end - fi->start;
fi->length = length;
/*
* You cannot just make the "len" field of a GByteArray
* larger, if there's no data to back that length;
* you can only make it smaller.
*/
if (fi->value.ftype->ftype == FT_BYTES && length <= (gint)fi->value.value.bytes->len)
fi->value.value.bytes->len = length;
finfo_set_len(fi, length);
}
int