Skip to content

Commit d0bae2b

Browse files
authored
Merge pull request #23557 from JuliaLang/rf/IntSet-symdiff-overflow
fix StackOverflowError in symdiff(::IntSet, ::NotInteger)
2 parents 7e2e6c9 + a848012 commit d0bae2b

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

base/intset.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,15 @@ symdiff(s::IntSet, ns) = symdiff!(copy(s), ns)
155155
156156
For each element in `itr`, destructively toggle its inclusion in set `s`.
157157
"""
158-
symdiff!(s::IntSet, ns) = (for n in ns; symdiff!(s, n); end; s)
158+
symdiff!(s::IntSet, ns) = (for n in ns; int_symdiff!(s, n); end; s)
159159
"""
160160
symdiff!(s, n)
161161
162162
The set `s` is destructively modified to toggle the inclusion of integer `n`.
163163
"""
164-
function symdiff!(s::IntSet, n::Integer)
164+
symdiff!(s::IntSet, n::Integer) = int_symdiff!(s, n)
165+
166+
function int_symdiff!(s::IntSet, n::Integer)
165167
0 < n < typemax(Int) || _throw_intset_bounds_err()
166168
val = !(n in s)
167169
_setint!(s, n, val)

test/intset.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ end
9090
# issue #23099 : these tests should not segfault
9191
@test_throws ArgumentError symdiff!(IntSet(rand(1:100, 30)), 0)
9292
@test_throws ArgumentError symdiff!(IntSet(rand(1:100, 30)), [0, 2, 4])
93+
94+
# issue #23557 :
95+
@test_throws MethodError symdiff!(IntSet([1]), ['a']) # should no stack-overflow
96+
@test_throws MethodError symdiff!(IntSet([1, 2]), [[1]]) # should not return IntSet([2])
9397
end
9498

9599
@testset "copy, copy!, similar" begin

0 commit comments

Comments
 (0)