Skip to content

Commit

Permalink
use correct size when creating output data from an IOBuffer (#54129)
Browse files Browse the repository at this point in the history
PR from #54097.

Fixes #54097

Co-authored-by: Nathan Zimmerberg
(cherry picked from commit fda02ac)
  • Loading branch information
KristofferC committed Apr 25, 2024
1 parent 08c7f9d commit 9b5f3c9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/iobuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ function take!(io::IOBuffer)
elseif io.writable
data = view(io.data, io.offset+1:nbytes+io.offset)
else
data = copyto!(StringVector(io.size), 1, io.data, io.offset + 1, nbytes)
data = copyto!(StringVector(nbytes), 1, io.data, io.offset + 1, nbytes)
end
else
nbytes = bytesavailable(io)
Expand Down
5 changes: 5 additions & 0 deletions test/iobuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,8 @@ end
seek(io,0)
@test Base.read_sub(io,v,1,1) == [1,0]
end

@testset "with offset" begin
b = pushfirst!([0x02], 0x01)
@test take!(IOBuffer(b)) == [0x01, 0x02]
end

0 comments on commit 9b5f3c9

Please sign in to comment.