From 03a2539b227ee2adc547b6c755cc1d17235a09b9 Mon Sep 17 00:00:00 2001 From: Dmitry Lazurkin Date: Sun, 20 Nov 2016 16:39:31 +0300 Subject: 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 Tested-by: Petri Dish Buildbot Reviewed-by: Michael Mann --- epan/proto.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'epan/proto.c') diff --git a/epan/proto.c b/epan/proto.c index cfd137d083..978008fa1f 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -5447,17 +5447,9 @@ proto_item_prepend_text(proto_item *pi, const char *format, ...) } } -void -proto_item_set_len(proto_item *pi, const gint length) +static void +finfo_set_len(field_info *fi, const gint length) { - field_info *fi; - - TRY_TO_FAKE_THIS_REPR_VOID(pi); - - fi = PITEM_FINFO(pi); - if (fi == NULL) - return; - DISSECTOR_ASSERT(length >= 0); fi->length = length; @@ -5470,6 +5462,20 @@ proto_item_set_len(proto_item *pi, const gint length) fi->value.value.bytes->len = length; } +void +proto_item_set_len(proto_item *pi, const gint length) +{ + field_info *fi; + + TRY_TO_FAKE_THIS_REPR_VOID(pi); + + fi = PITEM_FINFO(pi); + if (fi == NULL) + return; + + finfo_set_len(fi, length); +} + /* * Sets the length of the item based on its start and on the specified * offset, which is the offset past the end of the item; as the start @@ -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 -- cgit v1.2.1