[flang-commits] [flang] 91ee72d - [flang] Fix potential segfault in PointerAssociateRemapping
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Tue Feb 28 05:01:38 PST 2023
Author: Valentin Clement
Date: 2023-02-28T14:01:32+01:00
New Revision: 91ee72d10e9f64c8c046115c5cdf35e08dd6f70d
URL: https://github.com/llvm/llvm-project/commit/91ee72d10e9f64c8c046115c5cdf35e08dd6f70d
DIFF: https://github.com/llvm/llvm-project/commit/91ee72d10e9f64c8c046115c5cdf35e08dd6f70d.diff
LOG: [flang] Fix potential segfault in PointerAssociateRemapping
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
Added:
Modified:
flang/runtime/pointer.cpp
Removed:
################################################################################
diff --git a/flang/runtime/pointer.cpp b/flang/runtime/pointer.cpp
index 4cf8e92eb5add..5e1233386c608 100644
--- a/flang/runtime/pointer.cpp
+++ b/flang/runtime/pointer.cpp
@@ -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),
More information about the flang-commits
mailing list