BufferedFile bug?

Oskar Linde oskar.lindeREM at OVEgmail.com
Thu Mar 6 05:22:13 PST 2008


Regan Heath wrote:
> Hey,
> 
> [DMD 2.010, windows]
> 
> So.. was doing a bit of simple D coding and got some really odd 
> behaviour, namely this code creates a 4gb (4,294,975,895 bytes) file on 
> my disk!
> 
> My question is, is this a bug or am I doing something stupid?

Congratulations, you found another stupid integer promotion rule bug. 
Those have been a personal gripe for me. Hopefully we can one day fix 
this horrible design mistake from C.

The problem is that:

uint l = 1;
long c = -l;

yields c == 4294967295

wohoo... (Did I mention that I hate those?)

The error lies in BufferedStream.flush()

BufferedStream has a uint bufferSourcePos and does:

       if (bufferSourcePos != 0 && seekable) {
	// move actual file pointer to front of buffer
	streamPos = s.seek(-bufferSourcePos, SeekPos.Current);

and since seeks first argument is a long, it gets a value close to 4GB.

-- 
Oskar



More information about the Digitalmars-d mailing list