leftmike / foment

Foment is an implementation of R7RS Scheme.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

When using read-byte-vector on a file, the last bytes of the file are lost.

BernardTatin opened this issue · comments

For example, if you have a file of 23 bytes, the first read of 16 bytes is good. The second read of 16 bytes return eof-object? instead of a byte vector with the last 7 bytes. I found this flaw is in the function BufferedReadBytes, (file src/io.cpp), you have to replace :

            FAssert(bc->Buffer != 0);

            bc->Used = 0;
            bc->Available = ReadBytes(AsGenericPort(port)->Object, bc->Buffer, bc->Maximum);
            if (bc->Available == 0)
                return(0);    // BAD !

by :

            FAssert(bc->Buffer != 0);

            bc->Used = 0;
            bc->Available = ReadBytes(AsGenericPort(port)->Object, bc->Buffer, bc->Maximum);
            if (bc->Available == 0)
                return(br);    // GOOD !

You can see a tiny test on the fork of Foment I've done (test/byte-read.scm).

Have a nice day !

PS: I think it's a better place than mail.