Skip to content

Commit aaca5ba

Browse files
authored
Fix bug with negative time limits (#202)
1 parent 5982ae9 commit aaca5ba

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "GLPK"
22
uuid = "60bf3e95-4087-53dc-ae20-288a0d20c6a6"
33
repo = "https://github.com/jump-dev/GLPK.jl.git"
4-
version = "0.15.2"
4+
version = "0.15.3"
55

66
[deps]
77
BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232"

src/MOI_wrapper/MOI_wrapper.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ end
353353
MOI.supports(::Optimizer, ::MOI.TimeLimitSec) = true
354354

355355
_limit_sec_to_ms(::Nothing) = typemax(Int32)
356-
_limit_sec_to_ms(x::Real) = ceil(Int32, min(typemax(Int32), 1_000 * x))
356+
# Project the timelimit onto [0, typemax(Int32)] to avoid nasty segfaults.
357+
_limit_sec_to_ms(x::Real) = ceil(Int32, max(0, min(typemax(Int32), 1_000 * x)))
357358

358359
function MOI.set(
359360
model::Optimizer,

test/MOI_wrapper.jl

+7
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,13 @@ function test_empty_problem_unbounded()
464464
return
465465
end
466466

467+
function test_negative_timelimitsec()
468+
model = GLPK.Optimizer()
469+
MOI.set(model, MOI.TimeLimitSec(), -1.23)
470+
@test MOI.get(model, MOI.TimeLimitSec()) == 0.0
471+
return
472+
end
473+
467474
end # module
468475

469476
TestMOIWrapper.runtests()

0 commit comments

Comments
 (0)