IOExts.slurpFile fails on zero-length files
Volker Stolz
vs at lambda.foldr.org
Wed May 8 12:58:48 EDT 2002
On Wed, May 08, 2002 at 06:10:03PM +0200, George Russell wrote:
> 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.
I don't stand on any particular OS's side w.r.t. this issue. Indeed, I'd
second your suggestion, but that would mean more changes than simply
getting slurpFile to work.
Volker
More information about the Glasgow-haskell-bugs
mailing list