This is the mail archive of the cygwin-developers mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: stack overflow bug in ofstream::operator<<


On Thu, Jun 30, 2005 at 03:56:51PM +0200, Corinna Vinschen wrote:
>On Jun 30 15:54, Corinna Vinschen wrote:
>> Ok.  I take it then that you don't like the way I solved it.  Implementing
>> some alloca like function with exception handling is certainly more i386
>> assembler than I understand.
>
>Well, my solution would work as a replacement, too:
>
>#define ALLOCA(siz)     \
>        ({ \
>          extern unsigned long _size_of_stack_reserve__; \
>          register char *_curstack __asm__ ("%esp"); \
>          size_t size = (siz); \
>          ((size_t) ((_curstack - (_tlsbase \
>                                   - (size_t) &_size_of_stack_reserve__) \
>                    ) / 65536) * 65536 > size) ? alloca (size) : NULL;\
>        })

I don't think that _size_of_stack_reserve__ is correct since there is no
guarantee that a stack has allocated that much space.  As Dave said, I
think that this should be something like (untested):

  inline void * __attribute__ ((always_inline))
  alloca_check (size_t sz)
  {
    char *esp __asm__ ("%esp");
    return (esp - sz) >= _tlstop ? alloca (sz) : NULL;
  }

although I don't know if the always_inline will work if the inline
function calls alloca.  If not, then it would need to be a macro,
similar to the way you implemented it.

cgf


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]