Skip to content

Commit 9680bb1

Browse files
authored
Fix divide-by-zero distributing corpus with workers: 0 (#1583)
The corpus distribution introduced in 92b90d4 uses integer divMod by nFuzzWorkers, which throws on workers: 0 (symbolic-only mode, where the sym worker is the only worker and forces the corpus chunks). Guard the nFuzzWorkers == 0 case explicitly: there are no fuzz workers to distribute to, and the symbolic worker replays the full corpus anyway.
1 parent a23d1d9 commit 9680bb1

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

lib/Echidna/UI.hs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,16 @@ ui vm dict initialCorpus cliSelectedContract = do
8989
perWorkerTestLimit = ceiling
9090
(fromIntegral conf.campaignConf.testLimit / fromIntegral nFuzzWorkers :: Double)
9191

92-
(corpusChunkSize, largerCorpusChunks) = length initialCorpus `divMod` nFuzzWorkers
93-
corpusChunkSizes =
94-
replicate largerCorpusChunks (corpusChunkSize + 1) <>
95-
replicate (nFuzzWorkers - largerCorpusChunks) corpusChunkSize
96-
corpusChunks = splitPlaces corpusChunkSizes initialCorpus ++ repeat []
92+
-- Distribute the replay corpus across the fuzz workers. The symbolic
93+
-- worker always replays the full corpus (see spawnWorker), so with no
94+
-- fuzz workers there is nothing to distribute.
95+
corpusChunks
96+
| nFuzzWorkers == 0 = repeat []
97+
| otherwise = splitPlaces chunkSizes initialCorpus ++ repeat []
98+
where
99+
(baseSize, remainder) = length initialCorpus `divMod` nFuzzWorkers
100+
chunkSizes = replicate remainder (baseSize + 1)
101+
<> replicate (nFuzzWorkers - remainder) baseSize
97102

98103
corpusSaverStopVar <- spawnListener (saveCorpusEvent env)
99104

0 commit comments

Comments
 (0)