Ethereal-dev: Re: [Ethereal-dev] Novell NDS decodes

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: Tue, 8 Oct 2002 12:45:08 -0700
On Tue, Oct 08, 2002 at 03:21:26AM -0700, Guy Harris wrote:
> You will have to make "get_string()" allocate a buffer, using
> "g_malloc()", to hold the string, and return a pointer to that buffer.
> 
> You will also have to make sure that buffer gets freed when it's no
> longer needed.
> 
> Unfortunately, as "global_object_name" is set to point to data extracted
> with "get_string()", and as the code to use the result of "get_string()"
> is sometimes not near the call to "get_string()", doing so is hard in
> some cases.

Another possibility would be to define a structure with a "char *" and a
"size_t", where the "char *" points to a string buffer and the "size_t"
is the current length of the buffer.  Have "get_string()" take as an
argument a pointer to that structure, and grow the buffer if it's not
big enough for the string it'll be fetching.

That'd mean you wouldn't have to worry about freeing the buffer (it'd
stay around as long as Ethereal or Tethereal was running).