BufferedFile bug?
Regan Heath
regan at netmail.co.nz
Tue Mar 11 08:47:32 PDT 2008
Oskar Linde wrote:
> 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.
When the file ended up that close to 4gb each time I did suspect an
signed/unsigned bug. Did anyone make a bug report or should I do so now?
Regan
More information about the Digitalmars-d
mailing list