peekCString crashes on handling nullPtr
Not quite sure what the 'correct' behaviour here is; but here's a minimal test case:
-bash-3.2$ more TestCase.hs
import Foreign
import Foreign.C
main = do
str <- peekCString nullPtr
putStrLn str
-bash-3.2$ ghc --make TestCase.hs
-bash-3.2$ ./TestCase
Segmentation fault
I was not expecting a seg fault here. At minimum, peekCString documentation should describe what is meant to happen when you pass it a nullPtr (currently not mentioned at all). Better would be some form of error reporting - I'm integrating with a C library, and it took me a while to track down what the root cause of the seg fault was.
Trac metadata
| Trac field | Value |
|---|---|
| Version | 6.12.3 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (FFI) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |