@@ -52,9 +52,11 @@ class ShiftControl {
52
52
}
53
53
}
54
54
}
55
+ } else if (auto count{GetInt64Safe (
56
+ shift_.OffsetElement <char >(), shiftElemLen_, terminator_)}) {
57
+ shiftCount_ = *count;
55
58
} else {
56
- shiftCount_ =
57
- GetInt64 (shift_.OffsetElement <char >(), shiftElemLen_, terminator_);
59
+ terminator_.Crash (" %s: SHIFT= value exceeds 64 bits" , which);
58
60
}
59
61
}
60
62
RT_API_ATTRS SubscriptValue GetShift (const SubscriptValue resultAt[]) const {
@@ -67,8 +69,10 @@ class ShiftControl {
67
69
++k;
68
70
}
69
71
}
70
- return GetInt64 (
71
- shift_.Element <char >(shiftAt), shiftElemLen_, terminator_);
72
+ auto count{GetInt64Safe (
73
+ shift_.Element <char >(shiftAt), shiftElemLen_, terminator_)};
74
+ RUNTIME_CHECK (terminator_, count.has_value ());
75
+ return *count;
72
76
} else {
73
77
return shiftCount_; // invariant count extracted in Init()
74
78
}
@@ -719,12 +723,15 @@ void RTDEF(Reshape)(Descriptor &result, const Descriptor &source,
719
723
std::size_t resultElements{1 };
720
724
SubscriptValue shapeSubscript{shape.GetDimension (0 ).LowerBound ()};
721
725
for (int j{0 }; j < resultRank; ++j, ++shapeSubscript) {
722
- resultExtent[j] = GetInt64 (
723
- shape.Element <char >(&shapeSubscript), shapeElementBytes, terminator);
724
- if (resultExtent[j] < 0 ) {
726
+ auto extent{GetInt64Safe (
727
+ shape.Element <char >(&shapeSubscript), shapeElementBytes, terminator)};
728
+ if (!extent) {
729
+ terminator.Crash (" RESHAPE: value of SHAPE(%d) exceeds 64 bits" , j + 1 );
730
+ } else if (*extent < 0 ) {
725
731
terminator.Crash (" RESHAPE: bad value for SHAPE(%d)=%jd" , j + 1 ,
726
- static_cast <std::intmax_t >(resultExtent[j] ));
732
+ static_cast <std::intmax_t >(*extent ));
727
733
}
734
+ resultExtent[j] = *extent;
728
735
resultElements *= resultExtent[j];
729
736
}
730
737
@@ -762,14 +769,16 @@ void RTDEF(Reshape)(Descriptor &result, const Descriptor &source,
762
769
SubscriptValue orderSubscript{order->GetDimension (0 ).LowerBound ()};
763
770
std::size_t orderElementBytes{order->ElementBytes ()};
764
771
for (SubscriptValue j{0 }; j < resultRank; ++j, ++orderSubscript) {
765
- auto k{GetInt64 (order->Element <char >(&orderSubscript), orderElementBytes,
766
- terminator)};
767
- if (k < 1 || k > resultRank || ((values >> k) & 1 )) {
772
+ auto k{GetInt64Safe (order->Element <char >(&orderSubscript),
773
+ orderElementBytes, terminator)};
774
+ if (!k) {
775
+ terminator.Crash (" RESHAPE: ORDER element value exceeds 64 bits" );
776
+ } else if (*k < 1 || *k > resultRank || ((values >> *k) & 1 )) {
768
777
terminator.Crash (" RESHAPE: bad value for ORDER element (%jd)" ,
769
- static_cast <std::intmax_t >(k));
778
+ static_cast <std::intmax_t >(* k));
770
779
}
771
- values |= std::uint64_t {1 } << k;
772
- dimOrder[j] = k - 1 ;
780
+ values |= std::uint64_t {1 } << * k;
781
+ dimOrder[j] = * k - 1 ;
773
782
}
774
783
} else {
775
784
for (int j{0 }; j < resultRank; ++j) {
0 commit comments