Skip to content

Commit 4958e57

Browse files
committed
Fixed Segmentation fault caused by convertDataType
Implemented temporary convertDataType2
1 parent 147335a commit 4958e57

File tree

1 file changed

+13
-3
lines changed
  • examples/multi-size-malloc/source

1 file changed

+13
-3
lines changed

examples/multi-size-malloc/source/main.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,22 @@ constexpr auto isSpan(T<TType, TExtent>) {
164164

165165
template <typename TNew, typename TOld, std::size_t TExtent>
166166
constexpr auto convertDataType(std::span<TOld, TExtent>& range) {
167+
if constexpr(TExtent == std::dynamic_extent) {
168+
return std::span<TNew>(
169+
reinterpret_cast<TNew*>(range.data()), range.size() * sizeof(TOld) / sizeof(TNew)
170+
);
171+
}
167172
return std::span<TNew, TExtent * sizeof(TOld) / sizeof(TNew)>(
168173
reinterpret_cast<TNew*>(range.data()), range.size());
169174
}
170175

176+
template <typename TNew, typename TOld>
177+
constexpr auto convertDataType2(std::span<TOld>& range) {
178+
return std::span<TNew>(
179+
reinterpret_cast<TNew*>(range.data()), range.size() * sizeof(TOld) / sizeof(TNew)
180+
);
181+
}
182+
171183
struct IotaReductionChecker {
172184
uint32_t currentValue{};
173185

@@ -179,9 +191,7 @@ struct IotaReductionChecker {
179191
if (range.data() == nullptr) {
180192
return std::make_tuple(Actions::CHECK, Payload(std::make_pair(false, Reason::nullpointer)));
181193
}
182-
auto uintRange = convertDataType<uint32_t>(range);
183-
184-
// TODO: Segmentation fault by std::iota
194+
auto uintRange = convertDataType2<uint32_t>(range);
185195
std::iota(std::begin(uintRange), std::end(uintRange), currentValue);
186196
size_t n = uintRange.size();
187197

0 commit comments

Comments
 (0)