tal00r at ecs.soton.ac.uk
Tue Jan 28 10:54:01 CET 2003
On Mon, Jan 27, 2003 at 05:54:56PM -0600, edscott wilson garcia wrote:
> El lun, 27-01-2003 a las 12:23, Olivier Fourdan escribió:
> > On Mon, 2003-01-27 at 18:03, edscott wilson garcia wrote:
> > > I'm attaching a patch with the corrections made to your last patch, and
> > > as you can see the code losses simplicity and is much longer (KISS). In
> > > the original code, using 256 character strings on the stack might seem
> > > overkill, but it's really a tradeoff to cut out a lot of code. POSIX
> > > says that paths are no more than 255, so there is really no segv
> > > posibility here.
> > Well I did not follow your thread, but what I can say is I definitely
> > prefer allocating a char* on the fly with the correct length to hold to
> > path rather than using fixed array length. It could be slower on
> > alloc/free, but definitely more secure. Nothing is worst than trying to
> > track down strings overruns of a single (or more) bytes because it can
> > very well work on some architectures and crash on other.
> I must admit I used to think as you, but it's Thomas Leonard's fault
> that I combine both tecniques (reading code from rox filer I noticed he
> uses buffers of 4096, to hold stuff much smaller).
We only do this when there's no way to know how much memory to allocate in
advance, eg when calling gethostname, and we always reallocate it onto the
heap once we've got it. I'm pretty sure we have no fixed-size buffers that
aren't only allocated very briefly on the stack for this purpose...
Thomas Leonard http://rox.sourceforge.net
tal00r at ecs.soton.ac.uk tal197 at users.sourceforge.net
GPG: 9242 9807 C985 3C07 44A6 8B9A AE07 8280 59A5 3CC1
More information about the Xfce4-dev