Skip to content

Commit

Permalink
avoid overflowing show for OffsetArrays around typemax (#55303)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbauman committed Jul 31, 2024
1 parent c66513f commit f225f84
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1407,11 +1407,11 @@ function show_delim_array(io::IO, itr::Union{AbstractArray,SimpleVector}, op, de
x = itr[i]
show(recur_io, x)
end
i += 1
if i > l
if i == l
delim_one && first && print(io, delim)
break
end
i += 1
first = false
print(io, delim)
print(io, ' ')
Expand Down
9 changes: 9 additions & 0 deletions test/offsetarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,15 @@ end
@test CartesianIndices(A) == CartesianIndices(B)
end

@testset "overflowing show" begin
A = OffsetArray(repeat([1], 1), typemax(Int)-1)
b = IOBuffer(maxsize=10)
show(b, A)
@test String(take!(b)) == "[1]"
show(b, (A, A))
@test String(take!(b)) == "([1], [1])"
end

@testset "indexing views (#53249)" begin
v = view([1,2,3,4], :)
@test v[Base.IdentityUnitRange(2:3)] == OffsetArray(2:3, 2:3)
Expand Down

0 comments on commit f225f84

Please sign in to comment.