Skip to content

Commit

Permalink
add assertion that dynamicSubIndex is in range
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Jul 8, 2021
1 parent eb83a8b commit 192c835
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions include/llama/mapping/OffsetTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@ namespace llama::mapping
return reinterpret_cast<const EndOffsetType&>(
*mapToAddress<MappingIndex>(ResolvedRecordCoord{}, unresolvedBeforeDynamic, prevCoord, blobs));
};
auto loadEndOffset = [&](auto unresolvedBeforeDynamic) -> EndOffsetType
{
return reinterpret_cast<const EndOffsetType&>(
*mapToAddress<MappingIndex>(ResolvedRecordCoord{}, unresolvedBeforeDynamic, coord, blobs));
};

using Tag = GetTag<RecordDim, ResolvedSoFar>;
if constexpr (internal::isEndOffsetField<Tag>)
Expand All @@ -290,11 +295,7 @@ namespace llama::mapping
{
// compute size from end offset and prev end offset (or 0 for the first sub array)
const auto begin = loadBeginOffset(internal::OffsetLastCoord<UnresolvedBeforeDynamic, -2>{});
const auto end = reinterpret_cast<const EndOffsetType&>(*mapToAddress<MappingIndex>(
ResolvedRecordCoord{},
internal::OffsetLastCoord<UnresolvedBeforeDynamic, -2>{},
coord,
blobs));
const auto end = loadEndOffset(internal::OffsetLastCoord<UnresolvedBeforeDynamic, -2>{});
return static_cast<SizeType>(end - begin);
}
else if constexpr (std::is_same_v<UnresolvedBeforeDynamic, UnresolvedRecordCoord>)
Expand All @@ -312,6 +313,7 @@ namespace llama::mapping
constexpr auto nextSubMappingIndex = boost::mp11::mp_find<SplitCoords, ShiftedCoord>::value + 1;
static_assert(nextSubMappingIndex < boost::mp11::mp_size<MappedSubRecordDims>::value);
const auto dynamicSubIndex = loadBeginOffset(UnresolvedBeforeDynamic{}) + dynamicArrayExtents[0];
assert((dynamicSubIndex < loadEndOffset(UnresolvedBeforeDynamic{})) && "Dynamic index out of range");
return computeRecursive<nextSubMappingIndex>(
Cat<ResolvedSoFar, RecordCoord<dynamic>>{},
UnresolvedAfterDynamic{},
Expand Down

0 comments on commit 192c835

Please sign in to comment.