Skip to content

Commit 08ddb41

Browse files
nhz2KristofferC
authored andcommitted
Fix IOBuffer skip regression (#57963)
Fixes #57962 This reverts the changes to `skip` added in #57570 The code before #57570 was written in a very specific way to avoid overflow errors, so I'm not sure why this was changed. (cherry picked from commit b29c808)
1 parent 10b4ba1 commit 08ddb41

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

base/iobuffer.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,8 @@ function skip(io::GenericIOBuffer, n::Int)
486486
else
487487
# Don't use seek in order to allow a non-seekable IO to still skip bytes.
488488
# Handle overflow.
489-
maxptr = io.size + 1
490-
io.ptr = n > maxptr || io.ptr - n > maxptr ? maxptr : io.ptr + n
489+
n_max = io.size + 1 - io.ptr
490+
io.ptr += min(n, n_max)
491491
io
492492
end
493493
end

test/iobuffer.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,13 @@ end
497497
end
498498
end
499499

500+
@testset "issue #57962" begin
501+
io = IOBuffer(repeat("x", 400))
502+
skip(io, 10)
503+
skip(io, 400)
504+
@test isempty(read(io))
505+
end
506+
500507
@testset "pr #11554" begin
501508
io = IOBuffer(SubString("***αhelloworldω***", 4, 16))
502509
io2 = IOBuffer(Vector{UInt8}(b"goodnightmoon"), read=true, write=true)

0 commit comments

Comments
 (0)