diff --git a/CHANGELOG.md b/CHANGELOG.md index 753e2437..166b10f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Added missing equals and hashCode methods to SolutionCostPair. * Fixed end of line characters when writing weighted static scheduling instances to file. * WeightedStaticScheduling: fixed constants that should be static fields. +* Fixed potential int overflow in average computation in AbstractWeightedSelection. +* Fixed potential int overflow in average computation in AbstractStochasticSampler. ### Dependencies diff --git a/src/main/java/org/cicirello/search/evo/AbstractWeightedSelection.java b/src/main/java/org/cicirello/search/evo/AbstractWeightedSelection.java index 5388da09..f4f3c2be 100644 --- a/src/main/java/org/cicirello/search/evo/AbstractWeightedSelection.java +++ b/src/main/java/org/cicirello/search/evo/AbstractWeightedSelection.java @@ -99,7 +99,7 @@ final int selectOne(double[] normalizedWeights, int first, int last, double u) { if (last <= first) { return first; } - int mid = (first + last) >> 1; + int mid = (first + last) >>> 1; if (u < normalizedWeights[mid]) { return selectOne(normalizedWeights, first, mid, u); } else { diff --git a/src/main/java/org/cicirello/search/ss/AbstractStochasticSampler.java b/src/main/java/org/cicirello/search/ss/AbstractStochasticSampler.java index 41435a1d..f364eed3 100644 --- a/src/main/java/org/cicirello/search/ss/AbstractStochasticSampler.java +++ b/src/main/java/org/cicirello/search/ss/AbstractStochasticSampler.java @@ -142,7 +142,7 @@ final int select(double[] values, int k, double u) { int first = 0; int last = k - 1; while (first < last) { - int mid = (first + last) >> 1; + int mid = (first + last) >>> 1; if (u < values[mid]) { last = mid; } else {