aboutsummaryrefslogtreecommitdiffstats
path: root/epan/proto.c
diff options
context:
space:
mode:
authorJakub Zawadzki <darkjames-ws@darkjames.pl>2013-07-30 20:02:24 +0000
committerJakub Zawadzki <darkjames-ws@darkjames.pl>2013-07-30 20:02:24 +0000
commit430bd9eacc12309768b5a83114e297a2ce6c8c98 (patch)
treec8fb8cb7e76de7c86263e6854190b87563f836a6 /epan/proto.c
parente5997ef390c5875f99107c18c0a2e2d24d2c556d (diff)
Optimize marking label as truncated in proto_tree_set_representation_*()
svn path=/trunk/; revision=51036
Diffstat (limited to 'epan/proto.c')
-rw-r--r--epan/proto.c36
1 files changed, 14 insertions, 22 deletions
diff --git a/epan/proto.c b/epan/proto.c
index cceca60137..13c8293e61 100644
--- a/epan/proto.c
+++ b/epan/proto.c
@@ -3530,6 +3530,17 @@ alloc_field_info(proto_tree *tree, header_field_info *hfinfo, tvbuff_t *tvb, con
return new_field_info(tree, hfinfo, tvb, start, item_length);
}
+static void
+label_mark_truncated_start(char *label_str)
+{
+ static const char trunc_str[] = "[truncated] ";
+ const size_t trunc_len = sizeof(trunc_str)-1;
+
+ memmove(label_str + trunc_len, label_str, ITEM_LABEL_LENGTH - trunc_len);
+ memcpy(label_str, trunc_str, trunc_len);
+ label_str[ITEM_LABEL_LENGTH-1] = '\0';
+}
+
/* If the protocol tree is to be visible, set the representation of a
proto_tree entry with the name of the field for the item and with
the value formatted with the supplied printf-style format and
@@ -3575,18 +3586,8 @@ proto_tree_set_representation_value(proto_item *pi, const char *format, va_list
/* Uh oh, we don't have enough room. Tell the user
* that the field is truncated.
*/
- char *oldrep;
-
- /* Argh, we cannot reuse 'ap' here. So make a copy
- * of what we formatted for (re)use below.
- */
- oldrep = g_strdup(fi->rep->representation);
-
- g_snprintf(fi->rep->representation,
- ITEM_LABEL_LENGTH,
- "[truncated] %s",
- oldrep);
- g_free(oldrep);
+ /* XXX, label_mark_truncated() ? */
+ label_mark_truncated_start(fi->rep->representation);
}
}
}
@@ -3610,16 +3611,7 @@ proto_tree_set_representation(proto_item *pi, const char *format, va_list ap)
/* Uh oh, we don't have enough room. Tell the user
* that the field is truncated.
*/
- char *oldrep;
-
- /* Argh, we cannot reuse 'ap' here. So make a copy
- * of what we formatted for (re)use below.
- */
- oldrep = g_strdup(fi->rep->representation);
-
- g_snprintf(fi->rep->representation, ITEM_LABEL_LENGTH,
- "[truncated] %s", oldrep);
- g_free(oldrep);
+ label_mark_truncated_start(fi->rep->representation);
}
}
}