Skip to content

Commit

Permalink
Fix zero-length array concatenation validation (#45383)
Browse files Browse the repository at this point in the history
  • Loading branch information
BioTurboNick authored Jun 1, 2022
1 parent 1c7c000 commit 0a55a8e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 2 additions & 2 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2499,7 +2499,7 @@ function _typed_hvncat_shape(::Type{T}, shape::NTuple{N, Tuple}, row_first, as::
shapelength == lengthas || throw(ArgumentError("number of elements does not match shape; expected $(shapelength), got $lengthas)"))
# discover dimensions
nd = max(N, cat_ndims(as[1]))
outdims = zeros(Int, nd)
outdims = fill(-1, nd)
currentdims = zeros(Int, nd)
blockcounts = zeros(Int, nd)
shapepos = ones(Int, nd)
Expand All @@ -2524,7 +2524,7 @@ function _typed_hvncat_shape(::Type{T}, shape::NTuple{N, Tuple}, row_first, as::

isendblock = blockcounts[d] == shapev[d][shapepos[d]]
if isendblock
if outdims[d] == 0
if outdims[d] == -1
outdims[d] = currentdims[d]
elseif outdims[d] != currentdims[d]
throw(ArgumentError("argument $i has a mismatched number of elements along axis $ad; \
Expand Down
4 changes: 1 addition & 3 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1469,9 +1469,7 @@ using Base: typed_hvncat
v1 = zeros(Int, 0, 0, 0)
for v2 (1, [1])
for v3 (2, [2])
# current behavior, not potentially dangerous.
# should throw error like above loop
@test [v1 ;;; v2 v3] == [v2 v3;;;]
@test_throws ArgumentError [v1 ;;; v2 v3]
@test_throws ArgumentError [v1 ;;; v2]
@test_throws ArgumentError [v1 v1 ;;; v2 v3]
end
Expand Down

0 comments on commit 0a55a8e

Please sign in to comment.