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: Guy Harris <guy@xxxxxxxxxxxx>
Date: Mon, 25 Jan 2010 13:21:43 -0800
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);

> In the developers README file... it tells you NOT to use strcpy...but 
> instead use g_snprintf().

It doesn't say "don't use strncpy()".