Skip to content

Commit

Permalink
[flang] Fix potential segfault in PointerAssociateRemapping
Browse files Browse the repository at this point in the history
The bounds descriptor passed to the function is an array of [2, newRank]
size. Update the code so the rank is retrieved from the second dimension
and not the rank of the descriptor directly as it will be 2 in any case.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D144949
  • Loading branch information
clementval committed Feb 28, 2023
1 parent 905fa15 commit 91ee72d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions flang/runtime/pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ void RTNAME(PointerAssociateRemapping)(Descriptor &pointer,
Terminator terminator{sourceFile, sourceLine};
SubscriptValue byteStride{/*captured from first dimension*/};
std::size_t boundElementBytes{bounds.ElementBytes()};
pointer.raw().rank = bounds.rank();
for (int j{0}; j < bounds.rank(); ++j) {
std::size_t boundsRank{
static_cast<std::size_t>(bounds.GetDimension(1).Extent())};
pointer.raw().rank = boundsRank;
for (int j{0}; j < boundsRank; ++j) {
auto &dim{pointer.GetDimension(j)};
dim.SetBounds(GetInt64(bounds.ZeroBasedIndexedElement<const char>(2 * j),
boundElementBytes, terminator),
Expand Down

0 comments on commit 91ee72d

Please sign in to comment.