[Vm-dev] Bug in #instVarAt:put: for read-only objects
Eliot Miranda
eliot.miranda at gmail.com
Fri Jan 5 22:22:10 UTC 2018
Hi Tim,
> On Jan 5, 2018, at 11:45 AM, tim Rowledge <tim at rowledge.org> wrote:
>
>
>
>> On 05-01-2018, at 9:17 AM, Eliot Miranda <eliot.miranda at gmail.com> wrote:
>>
>>
>> The index and bounds validation should also occur, probably first. So something like
>>
>> Object>>instVarAt: index put: anObject
>> <primitive: 174 error: ec>
>> (index isInteger
>> and: [index between: 1 and: self class instSize + self basicSize]) ifFalse:
>> [self badIndexError: index].
>> self isReadOnlyObject ifTrue:
>> [^(NoModificationError for: self atInstVar: index with: anObject) signal].
>> self primitiveFailed
>
> Surely the no-modification check ought to come first since the index is completely irrelevant in that case?
No. That would mean that an attempted out-of-bounds access on a read-only object would raise the no modification error before the bounds violation which could cause a plausible implementation to turn the object into write mode but not be able that complete the write.
>
> And obviously we ought to be doing cleverer things with the returned error codes; we could avoid the all the tests here since the prim already provides error codes for bad argument (the index isInteger test), bad index (index bounds) and bad rcvr (immutability - though might we not want a specific error here instead?) I know, I know; somebody has to find the time to do the work.
:-)
>
> tim
> --
> tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
> Never forget: 2 + 2 = 5 for extremely large values of 2.
>
>
More information about the Vm-dev
mailing list