Bug in wordAtOffset:put:

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Bug in wordAtOffset:put:

Carsten Haerle
See my last post "Bug in dwordAtOffset:put". The same problem exists in
wordAtOffset:put: (but only once because there is no
basicWordAtOffset:put:).

#[0 0] wordAtOffset: 0 put: 16rFFFF "WORKS"
#[0 0] wordAtOffset: 0 put: (WORD fromInteger: 16rFFFF) "FAILS"

FIX:

!ByteArray methodsFor!

retryWordAtOffset: offset put: anObject
 "Private - Fallback code for storing unsigned word into the reciever when a
primitive fails.
 Either raises an appropriate error, or converts the argument to an Integer
and retries."

 | int |
 (self validateOffset: offset) == 2
  ifTrue:
   ["Not a suitable value - could be non-Numeric, or not in unsigned 16-bit
range.
  Attempt to coerce to Integer and retry. anObject may not understand
asInteger."
   int := anObject asInteger.
   (int >= 0 and: [int <= 16rFFFF]) ifTrue: [^self wordAtOffset: offset put:
int]].
 ^self errorCantHold: anObject! !
!ByteArray categoriesFor: #retryWordAtOffset:put:!accessing!private! !


Regards

Carsten Haerle