Skip to content

Commit

Permalink
Fix int overflow in amrex::bisect (AMReX-Codes#2964)
Browse files Browse the repository at this point in the history
Change from (lo+hi)/2 to lo+(hi-lo)/2.  Although it's very unlikely, it's
possible (lo+hi), where both lo and hi are integers, could overflow.
  • Loading branch information
WeiqunZhang committed Sep 28, 2022
1 parent e55d6b4 commit cd07b0d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Src/Base/AMReX_Algorithm.H
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ namespace amrex
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
I bisect (T const* d, I lo, I hi, T const& v) {
while (lo <= hi) {
int mid = (lo+hi)/2;
int mid = lo + (hi-lo)/2;
if (v >= d[mid] && v < d[mid+1]) {
return mid;
} else if (v < d[mid]) {
Expand Down

0 comments on commit cd07b0d

Please sign in to comment.