Wireshark-dev: Re: [Wireshark-dev] g_snprintf() and sizeof
From: Guy Harris <guy@xxxxxxxxxxxx>
Date: Thu, 19 Mar 2009 17:27:40 -0700

On Mar 19, 2009, at 1:54 PM, Stephen Fisher wrote:

Stop using fixed length strings so much? :-)

Even if we cast them now, I can see people adding sizeof in the future
and forgetting to cast it.  GLib doesn't appear to have any other
solution.

I suspect a lot of the g_snprintf() is to generate formatted strings and put them into places such as the Info column and the display form of protocol tree items, and I suspect a lot of those calls generate strings by producing an initial string and appending to them. The idiom used for the latter is really ugly.

GLib has the GString type, which, other than doing g_mallocs which could leak if the dissector throws an exception, are probably the right type for this. Perhaps we should create an ep_string type or something such as that, which is a string similar to a GString to which you can append stuff, with the string expanding as necessary, and use that to replace those g_snprintf()s?