From a620a4e17a43c91d6e87c9ffa0d20fb1bab15296 Mon Sep 17 00:00:00 2001 From: Matt Bauman Date: Wed, 31 Jul 2024 05:06:39 -0400 Subject: [PATCH] avoid overflowing show for OffsetArrays around typemax (#55303) (cherry picked from commit f225f8428f1a0d34cf837ee40bb2380b515eabab) --- base/show.jl | 4 ++-- test/offsetarray.jl | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/base/show.jl b/base/show.jl index 6db661879f791..6e9089f6a3b99 100644 --- a/base/show.jl +++ b/base/show.jl @@ -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, ' ') diff --git a/test/offsetarray.jl b/test/offsetarray.jl index c447c6d420f2a..ed9bf582e633b 100644 --- a/test/offsetarray.jl +++ b/test/offsetarray.jl @@ -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