From 50911770762e9595dc6331078c37f4e18e0ac7c2 Mon Sep 17 00:00:00 2001 From: Rafael Fourquet Date: Fri, 24 Jul 2020 01:15:30 +0200 Subject: [PATCH] fix stackoverflow in circshift!(x, y, (1.0,)) (#36734) (cherry picked from commit 773ef663957e1c7408e162acfa57a00c31b1534f) --- base/multidimensional.jl | 4 +++- test/arrayops.jl | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/base/multidimensional.jl b/base/multidimensional.jl index e26ae13664f2b8..b16a203ed6dac4 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -999,7 +999,9 @@ See also [`circshift`](@ref). axes(dest) == inds || throw(ArgumentError("indices of src and dest must match (got $inds and $(axes(dest)))")) _circshift!(dest, (), src, (), inds, fill_to_length(shiftamt, 0, Val(N))) end -circshift!(dest::AbstractArray, src, shiftamt) = circshift!(dest, src, (shiftamt...,)) + +circshift!(dest::AbstractArray, src, shiftamt) = + circshift!(dest, src, map(Integer, (shiftamt...,))) # For each dimension, we copy the first half of src to the second half # of dest, and the second half of src to the first half of dest. This diff --git a/test/arrayops.jl b/test/arrayops.jl index e8acde4c8826e3..256b186b517a16 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -733,6 +733,15 @@ end dst=similar(src) s=(1,2,3) @inferred Base.circshift!(dst,src,s) + + src = [1 2 3; 4 5 6] + dst = similar(src) + @test circshift(src, (3, 2)) == [5 6 4; 2 3 1] + @test circshift(src, (3.0, 2.0)) == [5 6 4; 2 3 1] + res = circshift!(dst, src, (3, 2)) + @test res === dst == [5 6 4; 2 3 1] + res = circshift!(dst, src, (3.0, 2.0)) + @test res === dst == [5 6 4; 2 3 1] end @testset "circcopy" begin