From 8f9fa49a1af35bf9ebc3951246a7e654463b7859 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Miclu=C8=9Ba-C=C3=A2mpeanu?= Date: Wed, 16 Oct 2024 01:59:50 +0300 Subject: [PATCH] fix: fix possible `StackOverflowError`s for `remake_buffer` & `InitializationProblem`s For `InitializationProblem`s `state_values(prob)` can return `nothing`, so calls like `remake_buffer(prob, state_values(prob), keys(u0), values(u0))` would lead to `StackOverflowError`s due to the fallback for the deprecated `Dict` method. This can crash julia if depwarns are enabled. --- src/remake.jl | 2 ++ test/remake_test.jl | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/remake.jl b/src/remake.jl index f640ac7..c1dbc47 100644 --- a/src/remake.jl +++ b/src/remake.jl @@ -55,6 +55,8 @@ function remake_buffer(sys, oldbuffer::AbstractArray, idxs, vals) return newbuffer end +remake_buffer(sys, ::Nothing, idxs, vals) = nothing + function remake_buffer(sys, oldbuffer, idxs, vals) remake_buffer(sys, oldbuffer, Dict(idxs .=> vals)) end diff --git a/test/remake_test.jl b/test/remake_test.jl index e7312c3..ce261c2 100644 --- a/test/remake_test.jl +++ b/test/remake_test.jl @@ -71,3 +71,5 @@ for (buf, newbuf, idxs, vals) in [ @test newbuf == _newbuf # test values @test typeof(newbuf) == typeof(_newbuf) # ensure appropriate type end + +@test isnothing(remake_buffer(sys, nothing, [], []))