Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Wireshark-dev: Re: [Wireshark-dev] string manipulation

From: Gerald Combs <gerald@xxxxxxxxxxxxx>
Date: Mon, 25 Jan 2010 13:31:46 -0800
Guy Harris wrote:
> On Jan 25, 2010, at 1:11 PM, Brian Oleksa wrote:
> 
>>                    char flowname[9];
>>                    strncpy(flowname, ptr, 8);
>>                    flowname[8] = '\0';
>>                    ptr += 8;
>>                    proto_tree_add_uint_format(helen_sub_tree, 
>> hf_helen_length, tvb, offset, 8, 0,
>>                            "Flowname: %s", flowname);
> 
> It's a string, not a number, so don't use proto_tree_add_uint_format(), or any other proto_tree_add_uint routine.
> 
> If it's an 8-octet field containing a null-padded string (presumably the string can have 8 octets), you should use something such as
> 
> 	proto_tree_add_string(helen_sub_tree, hf_helen_flowname, tvb, offset, 8, flowname);

Assuming hf_helen_flowname is an FT_STRING, couldn't you dispense with
the string-fetching and ptr-tracking entirely and just use

    proto_tree_add_item(helen_sub_tree, hf_helen_flowname, tvb,
        offset, 8, FALSE);

?