[Vm-dev] [Pharo-dev] Random corrupted data when copying from very large byte array
Alistair Grant
akgrant0710 at gmail.com
Tue Jan 23 15:40:49 UTC 2018
Hi Stu,
On 23 January 2018 at 16:15, Stuart Cassoff <aa72 at bell.net> wrote:
>
> I'm curious to test both of these problems on obsd but don't know what to do to make the problem manifest itself, so if anyone could toss me a (preferably non-null) pointer, that'd be great.
>
>
> Thanks,
>
> Stu
Just run #test4 (several times :-)) as defined in the original post.
Cheers,
Alistair
--
test4
"self test4"
| species bufferSize buffer totalRead outputStream answer inputStream ba byte1 |
ba := ByteArray new: 18202085. ba atAllPut: 99.
1 to: 20 do: [ :i | ba at: i put: (#[80 75 3 4 10 7 7 7 7 7 125 83
67 73 7 7 7 7 7 7] at: i) ]. inputStream := ba readStream.
bufferSize := 16384. species := ByteArray.
buffer := species new: bufferSize.
totalRead := 0.
outputStream := nil.
[ inputStream atEnd ] whileFalse: [ | readCount |
readCount := inputStream readInto: buffer startingAt: 1 count:
bufferSize.
totalRead = 0 ifTrue: [
byte1 := buffer first.
].
totalRead := totalRead + readCount.
outputStream ifNil: [
inputStream atEnd
ifTrue: [ ^ buffer copyFrom: 1 to: readCount ]
ifFalse: [ outputStream := (species new: bufferSize)
writeStream ] ].
outputStream next: readCount putAll: buffer startingAt: 1.
byte1 = outputStream contents first ifFalse: [ self halt ].
].
answer := outputStream ifNil: [ species new ] ifNotNil: [
outputStream contents ].
byte1 = answer first ifFalse: [ self halt ]. ^answer
--
More information about the Vm-dev
mailing list