IOExts.slurpFile fails on zero-length files

George Russell ger at tzi.de
Wed May 8 12:10:03 EDT 2002


Volker Stolz wrote:
[snip]
> Unluckily it doesn't look easy to make 'hGetBuf' fail more gracefully
> (you could read 0 bytes after all), because then still the
> 'mallocBytes 0' in 'slurpFile' will probably fail -- to quote FreeBSD's
> man page for malloc:
> 
> "It can be argued that returning a NULL pointer when asked to allocate
>      zero bytes is a silly response to a silly question."
I think it could be argued that FreeBSD page is wrong.  Functions should
return consistent results where the arguments make mathematical sense, and 
not judge particular combinations as "silly".  This GHC bug is a very good 
example why.

I suggest that mallocBytes be altered to work when zero bytes are requested
(you can simply keep a special pointer for this purpose, which should of
course never be dereferenced), and 0 should be permitted as an argument to
hGetBuf.



More information about the Glasgow-haskell-bugs mailing list