Skip to content

Commit c5e0a3b

Browse files
jferreyra-scrmorozov
authored andcommitted
Update filters.cpp
Fixing missing life rage protection for the reverse filter.
1 parent 98f7cb2 commit c5e0a3b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/filters.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,12 @@ InternalValue SequenceAccessor::Filter(const InternalValue& baseVal, RenderConte
553553
auto size = listSize.value();
554554
InternalValueList resultList(size);
555555
for (std::size_t n = 0; n < size; ++n)
556-
resultList[size - n - 1] = list.GetValueByIndex(n);
556+
{
557+
auto resultVal = InternalValue(std::move( list.GetValueByIndex(n) ));
558+
if (baseVal.ShouldExtendLifetime())
559+
resultVal.SetParentData(baseVal);
560+
resultList[size - n - 1] = std::move(resultVal);
561+
}
557562
result = ListAdapter::CreateAdapter(std::move(resultList));
558563
}
559564
else
@@ -562,7 +567,12 @@ InternalValue SequenceAccessor::Filter(const InternalValue& baseVal, RenderConte
562567
auto it = list.begin();
563568
auto end = list.end();
564569
for (; it != end; ++it)
565-
resultList.push_back(*it);
570+
{
571+
auto resultVal = InternalValue(std::move( *it ));
572+
if (baseVal.ShouldExtendLifetime())
573+
resultVal.SetParentData(baseVal);
574+
resultList.push_back(std::move(resultVal));
575+
}
566576

567577
std::reverse(resultList.begin(), resultList.end());
568578
result = ListAdapter::CreateAdapter(std::move(resultList));

0 commit comments

Comments
 (0)