[Issue 6944] New: stdio.File.byLine can't handle an empty file

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Nov 13 19:57:43 PST 2011


http://d.puremagic.com/issues/show_bug.cgi?id=6944

           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
        AssignedTo: nobody at puremagic.com
        ReportedBy: jmdavisProg at gmx.com


--- Comment #0 from Jonathan M Davis <jmdavisProg at gmx.com> 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())
        writeln(line);
}


results in this output:

core.exception.AssertError at 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/libc.so.6(__libc_start_main+0xed) [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: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list