diff options
author | Martin Mathieson <martin.r.mathieson@googlemail.com> | 2012-09-19 16:56:59 +0000 |
---|---|---|
committer | Martin Mathieson <martin.r.mathieson@googlemail.com> | 2012-09-19 16:56:59 +0000 |
commit | d729f21ad293e7cf5bd295318b564853a7330f7f (patch) | |
tree | bc35df403bf5dbf3a106fedc44918241748a5032 /epan/proto.c | |
parent | a232ae9242177783bc260311b160d5110e809883 (diff) |
Revert r45005.
svn path=/trunk/; revision=45006
Diffstat (limited to 'epan/proto.c')
-rw-r--r-- | epan/proto.c | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/epan/proto.c b/epan/proto.c index e21bd0812d..511c6d9dd0 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -2585,38 +2585,42 @@ proto_tree_add_string_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, * field info update instead of only updating the representation as does * proto_item_append_text() */ +/* NOTE: this function will break with the TRY_TO_FAKE_THIS_ITEM() + * speed optimization. + * Currently only WSP use this function so it is not that bad but try to + * avoid using this one if possible. + * IF you must use this function you MUST also disable the + * TRY_TO_FAKE_THIS_ITEM() optimization for your dissector/function + * using proto_item_append_string(). + * Do that by faking that the tree is visible by calling + * proto_tree_set_visible(tree, TRUE) (see packet-wsp.c) + * BEFORE you create the item you are later going to use + * proto_item_append_string() on. + */ void proto_item_append_string(proto_item *pi, const char *str) { - field_info *fi = NULL; - size_t curlen; + field_info *fi; + header_field_info *hfinfo; + gchar *old_str, *new_str; - if (pi == NULL) { + if (!pi) return; - } - - fi = PITEM_FINFO(pi); - if (fi == NULL) { + if (!*str) return; - } - if (!PROTO_ITEM_IS_HIDDEN(pi)) { - /* - * If we don't already have a representation, - * generate the default representation. - */ - if (fi->rep == NULL) { - ITEM_LABEL_NEW(fi->rep); - proto_item_fill_label(fi, fi->rep->representation); - } + fi = PITEM_FINFO(pi); + DISSECTOR_ASSERT_HINT(fi, "proto_tree_set_visible(tree, TRUE) should have been called previously"); - curlen = strlen(fi->rep->representation); - if (ITEM_LABEL_LENGTH > curlen) { - g_strlcpy(fi->rep->representation + curlen, - str, - ITEM_LABEL_LENGTH - (gulong) curlen); - } + hfinfo = fi->hfinfo; + if (hfinfo->type == FT_PROTOCOL) { + /* TRY_TO_FAKE_THIS_ITEM() speed optimization: silently skip */ + return; } + DISSECTOR_ASSERT(hfinfo->type == FT_STRING || hfinfo->type == FT_STRINGZ); + old_str = fvalue_get(&fi->value); + new_str = ep_strdup_printf("%s%s", old_str, str); + fvalue_set(&fi->value, new_str, FALSE); } /* Set the FT_STRING value */ |