Skip to content

Commit

Permalink
Fix size on GenericMemory with non-Int Integer argument (#53161)
Browse files Browse the repository at this point in the history
I found this through fuzzing. The nature of the issue indicates to me
that this was untested, but coverage doesn't seem to have run for the
past three months so I can't check, which is why I added an explicit
test.

I'm not sure `arrayops.jl` is the best place for tests related to
`GenericMemory`, so feel free to suggest a better one.

Co-authored-by: Sukera <[email protected]>
  • Loading branch information
Seelengrab and Seelengrab authored Feb 2, 2024
1 parent f2e168a commit 98e4f01
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/genericmemory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ size(a::GenericMemory, d::Int) =
d < 1 ? error("dimension out of range") :
d == 1 ? length(a) :
1
size(a::GenericMemory, d::Integer) = size(a, convert(d, Int))
size(a::GenericMemory, d::Integer) = size(a, convert(Int, d))
size(a::GenericMemory) = (length(a),)

IndexStyle(::Type{<:GenericMemory}) = IndexLinear()
Expand Down
9 changes: 9 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3192,3 +3192,12 @@ end
@test_throws DimensionMismatch wrap(Array, memref2, 9)
@test_throws DimensionMismatch wrap(Array, memref2, 10)
end

@testset "Memory size" begin
len = 5
mem = Memory{Int}(undef, len)
@test size(mem, 1) == len
@test size(mem, 0x1) == len
@test size(mem, 2) == 1
@test size(mem, 0x2) == 1
end

0 comments on commit 98e4f01

Please sign in to comment.