Skip to content

Commit

Permalink
Small Bugfix: Remove possibility of bitshifting negative integers (#1111
Browse files Browse the repository at this point in the history
)

* remove possible bitshifts of negative numbers

* changelog
  • Loading branch information
lroberts36 authored Jun 18, 2024
1 parent 85ded14 commit da22529
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- [[PR 1004]](https://github.com/parthenon-hpc-lab/parthenon/pull/1004) Allow parameter modification from an input file for restarts

### Fixed (not changing behavior/API/variables/...)
- [[PR 1111]](https://github.com/parthenon-hpc-lab/parthenon/pull/1111) Fix undefined behavior due to bitshift of negative number in LogicalLocation
- [[PR 1092]](https://github.com/parthenon-hpc-lab/parthenon/pull/1092) Updates to DataCollection and MeshData to remove requirement of predefining MeshBlockData
- [[PR 1113]](https://github.com/parthenon-hpc-lab/parthenon/pull/1113) Prevent division by zero
- [[PR 1112]](https://github.com/parthenon-hpc-lab/parthenon/pull/1112) Remove shared_ptr cycle in forest::Tree
Expand Down
8 changes: 4 additions & 4 deletions src/mesh/forest/logical_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ bool LogicalLocation::IsNeighbor(const LogicalLocation &in) const {

bool neighbors = true;
for (int dir = 0; dir < 3; ++dir) {
auto low = (l(dir) << level_shift_this) - 1;
auto low = l(dir) * block_size_this - 1;
auto hi = low + block_size_this + 1;

auto low_in = (in.l(dir) << level_shift_in);
auto low_in = in.l(dir) * block_size_in;
auto hi_in = low_in + block_size_in - 1;
neighbors = neighbors && !(hi < low_in || low > hi_in);
}
Expand All @@ -140,7 +140,7 @@ bool LogicalLocation::IsNeighborOfTE(const LogicalLocation &in,

bool neighbors = true;
for (int dir = 0; dir < 3; ++dir) {
auto low = (l(dir) << level_shift_this);
auto low = l(dir) * block_size_this;
auto hi = low + block_size_this - 1;
if (te_offset[dir] == -1) {
low -= 1;
Expand All @@ -150,7 +150,7 @@ bool LogicalLocation::IsNeighborOfTE(const LogicalLocation &in,
low = hi - 1;
}

auto low_in = (in.l(dir) << level_shift_in);
auto low_in = in.l(dir) * block_size_in;
auto hi_in = low_in + block_size_in - 1;
neighbors = neighbors && !(hi < low_in || low > hi_in);
}
Expand Down

0 comments on commit da22529

Please sign in to comment.