#5071: GHCi crashes on large alloca/allocaBytes requests
---------------------------------+------------------------------------------
    Reporter:  guest             |        Owner:              
        Type:  bug               |       Status:  new         
    Priority:  normal            |    Milestone:              
   Component:  Compiler          |      Version:  7.0.3       
    Keywords:                    |     Testcase:              
   Blockedby:                    |   Difficulty:              
          Os:  Unknown/Multiple  |     Blocking:              
Architecture:  Unknown/Multiple  |      Failure:  None/Unknown
---------------------------------+------------------------------------------

Comment(by guest):

 I don't know if Haskell's `alloca` was intended to behave like C's
 `alloca`, but this is from the man page for `alloca` on my linux machine:

 {{{
  RETURN VALUE
        The alloca() function returns a pointer to the beginning of the
 allocated space.
  If the allocation causes stack overflow, program behavior is undefined.
 }}}

 The following program segfaults for me:
 {{{
 $ cat alloc.c
 #include <stdio.h>
 #include <stdlib.h>
 #include <limits.h>
 #include <alloca.h>

 int main() {


   int *p = alloca(INT_MAX);
   printf("p = %p\n", p);
   return 0;
 }
 }}}

 What initially attracted me to using `alloca` is that I thought it was
 equivalent to the pseudo-code: `bracket malloc free`.  Perhaps I had the
 wrong expectation and the FFI should be amended to say that `alloca`
 requests for too many bytes are undefined like the C variant?

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5071#comment:6>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to