From 280023dfc21a9da39a92db1e648b68d7824197b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Sun, 15 Mar 2020 08:59:17 +0100 Subject: [PATCH] Avoid potential overflow for dynamic task priority. --- source/vibe/core/task.d | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/vibe/core/task.d b/source/vibe/core/task.d index c422d8c..1fd1b22 100644 --- a/source/vibe/core/task.d +++ b/source/vibe/core/task.d @@ -996,7 +996,7 @@ package struct TaskScheduler { private void doYieldAndReschedule(Task task) { - auto tf = () @trusted { return task.taskFiber; } (); + import std.algorithm.comparison : min; // insert according to priority, limited to a priority // factor of 1:10 in case of heavy concurrency @@ -1006,7 +1006,7 @@ package struct TaskScheduler { // increase dynamic priority each time a task gets overtaken to // ensure a fair schedule - t.m_dynamicPriority += t.m_staticPriority; + t.m_dynamicPriority += min(t.m_staticPriority, uint.max - t.m_dynamicPriority); return false; });