[BUG][FIX] upToEnd in PositionableStream (sm)

Boris Gaertner Boris.Gaertner at gmx.net
Thu Feb 19 14:01:38 UTC 2004


This bug report is for Squeak 3.7 latest update #5707,
and also for earlier versions.

The method PositionableStream>>upToEnd does not
always reads up to the end of the stream. It stops as
soon as it encounters the element  nil.

The bug is demonstrated by the following
piece of code, which is best evaluated with
'inspect it':

 | aStream |
 aStream := ReadWriteStream on:  Array new.
 (Array with: #a with: #b with: nil with: #c)
    do: [:item | aStream nextPut: item].
 aStream reset.
 Array with: (aStream upToEnd )
           with:  aStream contents.

You see that #upToEnd confuses the  nil  at
stream position 3 with the end of  the stream.

In the method mentioned above we read:

 | newStream el |
 newStream _ WriteStream on: (collection species new: 100).
 [(el _ self next) == nil] whileFalse: [ newStream nextPut: el ].
 ^ newStream contents

The third line is wrong, it should read

 [self atEnd] whileFalse: [newStream nextPut: self next].

Background: 
When reading past the end of a stream, our implementations of  #next
answer the value nil, which is certainly questionable.
It is however not allowed to interpret  nil  as an  end-of-stream
token. Such an interpretation ignores that fact that  nil  is freely
useable just because it has no other meaning than just being nil
- the sole instance of UndefinedObject.

The attached change set fixes the bug. A test was posted
separately.

Greetings, 
Boris   

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PosStream-upToEnd.1.cs
Type: application/octet-stream
Size: 792 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20040219/a430a698/PosStream-upToEnd.1.obj


More information about the Squeak-dev mailing list