Summary: stdio.File.byLine can't handle an empty file
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos

--- Comment #0 from Jonathan M Davis <> 2011-11-13 19:56:59 
PST ---
This program

import std.file;
import std.stdio;

void main()
    std.file.write("empty.txt", "");
    auto file = File("empty.txt");

    foreach(line; file.byLine())

results in this output:

core.exception.AssertError@std/stdio.d(946): Bug in File.readln
./q(_d_assert_msg+0x1f) [0x4595cb]
./q(void std.stdio.File.ByLine!(char, char).ByLine.popFront()+0xa6) [0x4560a2]
./q(char[] std.stdio.File.ByLine!(char, char).ByLine.front()+0x4c) [0x455fec]
./q(_Dmain+0x87) [0x455e13]
./q(extern (C) int rt.dmain2.main(int, char**).void runMain()+0x17) [0x459bd7]
./q(extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void
delegate())+0x2a) [0x45977e]
./q(extern (C) int rt.dmain2.main(int, char**).void runAll()+0x42) [0x459c2a]
./q(extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void
delegate())+0x2a) [0x45977e]
./q(main+0xd3) [0x45970f]
/lib/ [0x7ff97772817d]d

The foreach should just not run, since it's effectively iterating over an empty
range, but apparently ByLine's empty doesn't check the possibility that EOF has
already been reached - just whether the file is open or not.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to