From: Joshua Blanton (jblanton@masaka.cs.ohiou.edu)
Date: 01/05/06
Date: Thu, 5 Jan 2006 13:42:40 -0500 From: Joshua Blanton <jblanton@masaka.cs.ohiou.edu> Subject: Re: tcptrace-bugs Static variable returns of HostName() are not consider by callers Message-ID: <20060105184240.GA15875@mauser.ipx.ath.cx>
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...).
--jtb
This archive was generated by hypermail 2.1.7 : 01/06/06 EST