Skip to content

Commit

Permalink
avoid overflowing show for OffsetArrays around typemax (#55303)
Browse files Browse the repository at this point in the history
(cherry picked from commit f225f84)
  • Loading branch information
mbauman authored and KristofferC committed Oct 9, 2024
1 parent beb0c7d commit a620a4e
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 @@ -1345,11 +1345,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 @@ -863,3 +863,12 @@ end
# this is fixed in #40038, so the evaluation of its CartesianIndices should work
@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

0 comments on commit a620a4e

Please sign in to comment.