Skip to content

Commit a620a4e

Browse files
mbaumanKristofferC
authored andcommitted
avoid overflowing show for OffsetArrays around typemax (#55303)
(cherry picked from commit f225f84)
1 parent beb0c7d commit a620a4e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

base/show.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,11 +1345,11 @@ function show_delim_array(io::IO, itr::Union{AbstractArray,SimpleVector}, op, de
13451345
x = itr[i]
13461346
show(recur_io, x)
13471347
end
1348-
i += 1
1349-
if i > l
1348+
if i == l
13501349
delim_one && first && print(io, delim)
13511350
break
13521351
end
1352+
i += 1
13531353
first = false
13541354
print(io, delim)
13551355
print(io, ' ')

test/offsetarray.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,3 +863,12 @@ end
863863
# this is fixed in #40038, so the evaluation of its CartesianIndices should work
864864
@test CartesianIndices(A) == CartesianIndices(B)
865865
end
866+
867+
@testset "overflowing show" begin
868+
A = OffsetArray(repeat([1], 1), typemax(Int)-1)
869+
b = IOBuffer(maxsize=10)
870+
show(b, A)
871+
@test String(take!(b)) == "[1]"
872+
show(b, (A, A))
873+
@test String(take!(b)) == "([1], [1])"
874+
end

0 commit comments

Comments
 (0)