From 1a1d11185b0e25e16cac3c1b5091f2047d57150d Mon Sep 17 00:00:00 2001 From: simonmar Date: Fri, 24 Aug 2001 14:41:09 +0000 Subject: [PATCH] [project @ 2001-08-24 14:41:09 by simonmar] correct off-by-one error in hGetStringBuffer --- ghc/compiler/utils/StringBuffer.lhs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ghc/compiler/utils/StringBuffer.lhs b/ghc/compiler/utils/StringBuffer.lhs index dfe061e..c72be06 100644 --- a/ghc/compiler/utils/StringBuffer.lhs +++ b/ghc/compiler/utils/StringBuffer.lhs @@ -129,11 +129,17 @@ hGetStringBuffer expand_tabs fname = do return (A# a#, read) #endif - let (A# a#) = a; (I# read#) = read + -- urk! slurpFile gives us a buffer that doesn't have room for + -- the sentinel. Assume it has a final newline for now, and overwrite + -- that with the sentinel. slurpFileExpandTabs (below) leaves room + -- for the sentinel. + let (A# a#) = a; + (I# read#) = read; + end# = read# -# 1# -- add sentinel '\NUL' - _casm_ `` ((char *)%0)[(int)%1]=(char)0; '' (A# a#) (I# (read# -# 1#)) - return (StringBuffer a# read# 0# 0#) + _casm_ `` ((char *)%0)[(int)%1]=(char)0; '' (A# a#) (I# end#) + return (StringBuffer a# end# 0# 0#) unsafeWriteBuffer :: StringBuffer -> Int# -> Char# -> StringBuffer unsafeWriteBuffer s@(StringBuffer a _ _ _) i# ch# = @@ -269,7 +275,7 @@ trySlurp handle sz_i chunk = #if __GLASGOW_HASKELL__ < 404 writeHandle handle handle_ #endif - return (chunk', rc+1 {-room for sentinel-}) + return (chunk', rc+1 {- room for sentinel -}) reAllocMem :: Addr -> Int -> IO Addr -- 1.7.10.4