[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [MiNT] another getcwd fix (includes previous patch)
On Tue, 2008-01-08 at 00:48 +0100, Vincent Rivière wrote:
> Hello, Alan.
>
> > Another problem with getcwd() is that it defines a variable sized buffer
> > for _path (which is non-ANSI as the note says).
> >
> > With gcc optimizations this gets messed up and crashes, probably due to
> > stack corruption.
>
> The variable sized array is non-ANSI, however it shouldn't crash !
> It may be a GCC bug, a MiNTLib bug, or once again a stack overflow !
As I said, it only crashes when using optimizations with GCC, i.e. -O or
greater. So it sounds like a GCC bug.
> If the size passed to __getcwd() is too big, the original version will
> allocate a buffer of that size on the stack, and may crash. You version
> uses malloc, so it is safer.
Right, which is why I prefer the patch.
> However, it would be interesting to know exactly what was the cause of
> the crash. Did you manage to make a small testcase reproducing that
> problem ?
I do have a testcase, but I've not delved into it to find why the
optimiser is causing the crash.
Given that the patch cures it and malloc's memory rather than from the
stack, I'm not inclined to go digging much further.
Alan.