Hi Ian,
Here is a bug report and proposed fix. It happens when you add an
element after copying OrderedCollection with zero size.
test code.
[
| a b |
a := OrderedCollection with: 'xxx' with: 'yyy'.
b := a copyFrom: 0 to: -1. "Copy zero size"
b addLast: 'addLast: OK'. "Error"
b println.
b := a copyFrom: 0 to: -1.
b addFirst: 'addFirst: OK'.
b println.
]
proposed fix.
--- function/objects/OrderedCollection.st (revision 418)
+++ function/objects/OrderedCollection.st (working copy)
@@ -64,6 +64,7 @@
delta := array size.
(self size == 0 and: [delta > 0]) ifTrue: [^self resetToEnd].
(self size * 2 < delta) ifTrue: [^self shiftToEnd].
+ delta := delta max: 1.
newArray := (array new: self size + delta) replaceFrom:
firstIndex + delta to: lastIndex + delta - 1 with: array startingAt:
firstIndex.
array := newArray.
firstIndex := firstIndex + delta.
@@ -74,7 +75,7 @@
[
(self size == 0 and: [array size > 0]) ifTrue: [^self resetToBeginning].
(self size * 2 < array size) ifTrue: [^self shiftToBeginning].
- array := (array new: self size + array size)
+ array := (array new: self size + (array size max: 1))
replaceFrom: firstIndex to: lastIndex - 1 with: array
startingAt: firstIndex;
yourself.
]
Cheers,
- Takashi
_______________________________________________
fonc mailing list
[email protected]
http://vpri.org/mailman/listinfo/fonc