Skip to content

Commit

Permalink
Merge pull request #661 from cicirello/fix
Browse files Browse the repository at this point in the history
Fixed potential int overflow in average computation
  • Loading branch information
cicirello authored Aug 4, 2023
2 parents 49ba4f3 + 476af82 commit 317e433
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 317e433

Please sign in to comment.