rts: Ensure that new capability count is > 0
authorBen Gamari <ben@smart-cactus.org>
Fri, 16 Jun 2017 19:23:07 +0000 (15:23 -0400)
committerBen Gamari <ben@smart-cactus.org>
Sun, 18 Jun 2017 20:47:28 +0000 (16:47 -0400)
The Haskell wrapper already checks this but we should also check it in the RTS
to catch non-Haskell callers. See #13832.

rts/Schedule.c

index b4f60f8..7950785 100644 (file)
@@ -2178,7 +2178,13 @@ setNumCapabilities (uint32_t new_n_capabilities USED_IF_THREADS)
     Capability *old_capabilities = NULL;
     uint32_t old_n_capabilities = n_capabilities;
 
-    if (new_n_capabilities == enabled_capabilities) return;
+    if (new_n_capabilities == enabled_capabilities) {
+        return;
+    } else if (new_n_capabilities <= 0) {
+        errorBelch("setNumCapabilities: Capability count must be positive");
+        return;
+    }
+
 
     debugTrace(DEBUG_sched, "changing the number of Capabilities from %d to %d",
                enabled_capabilities, new_n_capabilities);