www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1953] New: BufferedFile seek and flush dumps 4gb to disk


           Summary: BufferedFile seek and flush dumps 4gb to disk
           Product: D
           Version: 2.012
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: regan netmail.co.nz

The following code creates a 4gb+ size file on disk.  This appears to be the
result of a signed/unsigned problem inside a flush call somewhere in std.stream

import std.stdio;
import std.stream;
import std.file;
import std.random;

int main()
        // Create small file
        auto    f = new BufferedFile("test", FileMode.OutNew);
        int     size = 50000;

        for(int i = 0; i < size; i++)


        // Open and modify      
        f = new BufferedFile("test", FileMode.In | FileMode.Out);
        ulong   total = getSize("test");
        long    block = total/1000;
        long    offset;
        long    bytes;
        Random  gen;

        writefln("Total: %d,%d", total, block);

        for(int i = 0; i < 2; i++)
                offset = uniform!(long)(gen, 0L, block);
                bytes  = uniform!(long)(gen, 0L, block);

                writefln("Seek : %d,%d,%d", f.position, offset, bytes);


                writefln("Mod  : %d,%d", f.position, bytes);

                for(long j = 0; j < bytes; j++)

                writefln("Done : %d", f.position);

        writefln("Close: %d", f.position);



        return 0;

Mar 27 2008