Re: tcptrace-bugs Static variable returns of HostName() are not consider by callers

From: Shawn Ostermann (
Date: 01/05/06

Subject: Re: tcptrace-bugs Static variable returns of HostName() are not consider by callers 
Date: Thu, 05 Jan 2006 14:52:39 -0500
From: Shawn Ostermann <>
Message-Id: <>

Joshua Blanton <> wrote:

> Shawn Ostermann wrote:
> > > Hm, it seems to me that the suggested fix is sufficient... In the
> > > case of printf() (and any other function that would potentially
> > > re-use the pointer more than once in an instance) we need to do some
> > > clean-up - but in the case of printf(), the cleanup is trivial.
> > > Just split the line printed into multiple lines and it All Gets
> > > Better. Existing code is already safe from this bug, other than
> > > debug messages, so why not just fix the debug messages?
> >
> > Well, it's a religious/stylistic question, I guess. I hate using
> > dynamic memory for these things. When I encounter these situations, I
> > normally just change the routine to rotate through static buffers and
> > then document that it does it. That way it can be used safely multiple
> > times in printf().
> Well, if you split the printf() call into multiple printf() calls,
> you aren't using dynamic memory - right?
> This would prevent both the corruption issue *and* the increased
> number of static buffers - but it would require the programmer to
> remember that you can't call Hostname() twice in one printf(); I
> agree that your solution does prevent a programmer from having to
> worry about re-using Hostname() twice in a function call (although
> there will always be some N for which calling Hostname() N+1 times
> as arguments to a function will fail...).

I agree with everything that you say. It's an issue of clean
interfaces, tight code, and garbage collection. If this was written in
a language that had garbage collection, it wouldn't be an issue. My
hack - and I don't remember where I got it, but I've been using it for
years - is lazy (heuristic) garbage collection. I like it because it
doesn't force me to make debugging code long and ugly. I don't like
long blocks of debugging code and I don't like breaking lines apart for
stupid reasons like static memory problems.

In any case, I put my hack into the 4 routines in names.c that have this
'feature' and checked it back in. I'm still trying to figure out why I
can't get the regression check to work, though.


This archive was generated by hypermail 2.1.7 : 01/06/06 EST