Hi,
one of my students found the following bug:
the program below (which opens a file, reads a char
and closes it) results in the file size increasing
at each run!
---------------------
module Main where
import IO
import IOExts
main = openFile "hget.txt" ReadWriteMode >>= \h ->
printSize h >>
hGetChar h >>=
print >>
printSize h >>
hClose h
printSize h = hFileSize h >>=
print
---------------
(the same happens if you comment the printSize lines).
It only happens with files smaller than 2046 bytes,
I tested it under ghc-4.08.1 (Windows) or ghc-4.08 (solaris)
with similar behaviour.
Here are sample runs with the following file sizes:
a) only one character, no newline characters (file size is really 1):
haskell{camaragibe}63: ls -l hget.txt
-rw-r--r-- 1 haskell resgroup 1 Sep 21 17:41 hget.txt
haskell{camaragibe}64: ./main
1
'a'
1
haskell{camaragibe}65: ./main
2
'a'
2
haskell{camaragibe}66: ./main
2
'a'
2
haskell{camaragibe}67: ls -l hget.txt
-rw-r--r-- 1 haskell resgroup 2 Sep 21 17:41 hget.txt
[the file started with character 'a' and ended up with two 'a's.
It doesn't grow any more than that.]
b) file size with two letters ("ab") and a newline (file size is three):
haskell{camaragibe}108: ls -l hget.txt
-rw-r--r-- 1 haskell resgroup 3 Sep 21 17:47 hget.txt
haskell{camaragibe}109: ./main
3
'a'
4
haskell{camaragibe}110: ./main
4
'a'
6
haskell{camaragibe}111: ./main
6
'a'
10
haskell{camaragibe}112: ls -l hget.txt
-rw-r--r-- 1 haskell resgroup 10 Sep 21 17:47 hget.txt
haskell{camaragibe}113: od -t c hget.txt
0000000 a b \n b b \n b \n b b
0000012
[the file started with "ab\n" and
ghc starts writing 'b's and enters at the end of the file.]
under windows the behaviour changes slightly, due to the
the use of CR-LF instead of LF for new lines.
The file grows up until 2046 characters (solaris) and no more
magic characters seem to appear for files bigger than that!
cheers,
Andre.