From a20d426b96e7c1b337ae7865db9cbc290212e097 Mon Sep 17 00:00:00 2001 From: simonmar Date: Wed, 31 Oct 2001 12:26:17 +0000 Subject: [PATCH] [project @ 2001-10-31 12:26:17 by simonmar] Handle completely empty files without crashing in slurpFileExpandTabs. --- ghc/compiler/utils/StringBuffer.lhs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ghc/compiler/utils/StringBuffer.lhs b/ghc/compiler/utils/StringBuffer.lhs index f49449e..1aedc7b 100644 --- a/ghc/compiler/utils/StringBuffer.lhs +++ b/ghc/compiler/utils/StringBuffer.lhs @@ -198,9 +198,14 @@ slurpFileExpandTabs fname = do then ioError (userError "slurpFile: file too big") else do let sz_i = fromInteger sz - sz_i' = (sz_i * 12) `div` 10 -- add 20% for tabs - chunk <- allocMem sz_i' - trySlurp handle sz_i' chunk + if sz_i == 0 + -- empty file: just allocate a buffer containing '\0' + then do chunk <- allocMem 1 + writeCharOffAddr chunk 0 '\0' + return (chunk, 0) + else do let sz_i' = (sz_i * 12) `div` 10 -- add 20% for tabs + chunk <- allocMem sz_i' + trySlurp handle sz_i' chunk ) trySlurp :: Handle -> Int -> Addr -> IO (Addr, Int) -- 1.7.10.4