Skip to content

Commit f225f84

Browse files
authored
avoid overflowing show for OffsetArrays around typemax (#55303)
1 parent c66513f commit f225f84

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

base/show.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1407,11 +1407,11 @@ function show_delim_array(io::IO, itr::Union{AbstractArray,SimpleVector}, op, de
14071407
x = itr[i]
14081408
show(recur_io, x)
14091409
end
1410-
i += 1
1411-
if i > l
1410+
if i == l
14121411
delim_one && first && print(io, delim)
14131412
break
14141413
end
1414+
i += 1
14151415
first = false
14161416
print(io, delim)
14171417
print(io, ' ')

test/offsetarray.jl

+9
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,15 @@ end
865865
@test CartesianIndices(A) == CartesianIndices(B)
866866
end
867867

868+
@testset "overflowing show" begin
869+
A = OffsetArray(repeat([1], 1), typemax(Int)-1)
870+
b = IOBuffer(maxsize=10)
871+
show(b, A)
872+
@test String(take!(b)) == "[1]"
873+
show(b, (A, A))
874+
@test String(take!(b)) == "([1], [1])"
875+
end
876+
868877
@testset "indexing views (#53249)" begin
869878
v = view([1,2,3,4], :)
870879
@test v[Base.IdentityUnitRange(2:3)] == OffsetArray(2:3, 2:3)

0 commit comments

Comments
 (0)