Ethereal-dev: Re: [Ethereal-dev] Re: [Ethereal-cvs] rev 15660: /trunk/plugins/asn1/: packet-a

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: "Guy Harris" <gharris@xxxxxxxxx>
Date: Thu, 1 Sep 2005 16:24:19 -0700 (PDT)
Ulf Lamping wrote:
> sahlberg@xxxxxxxxxxxx wrote:
> g_snprintf(str, 128-(str-string), "%s%u", prepend_comma?",":"",
>
> The expression "128-(str-string)" is exactly which should be avoided!!!
>
> This way of coding is *very* error intensive, at least when changes are
> made to the sources later.

Yes, it's a somewhat awkward idiom, possibly leaving more room for errors.

It also means the dissector imposes a limit on the length of the string.

> Maybe copying the GString code from GLib and replace the g_malloc calls
> by ep_malloc (well and change the prefix g_string_ to something like
> ep_string_ or course)?

Or, alternatively, implementing an emem-based asprintf-style API, perhaps
using g_printf_string_upper_bound()?

Another possibility is to use proto_item_append_text() - put the initial
information into an item created with a proto_tree_add_ routine, and then
append to it.