Skip to content

Commit 9f948fc

Browse files
rshestfacebook-github-bot
authored andcommitted
Fix potential use after move in Differentiator (#36537)
Summary: Pull Request resolved: #36537 ##Changelog: [Internal] - This popped up when I was landing D44172494. Order of arguments evaluation to a function call in C++ is unspecified, therefore there was a potential danger of use after move in two places in `Differentiator.cpp` This diff fixes it. Reviewed By: javache Differential Revision: D44215210 fbshipit-source-id: 828ca379e2ba5a40506f1ff3136150af63ea1ff7
1 parent 59243aa commit 9f948fc

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/react-native/ReactCommon/react/renderer/mounting/Differentiator.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,10 @@ static void updateMatchedPairSubtrees(
487487
sliceChildShadowNodeViewPairsFromViewNodePair(oldPair, innerScope);
488488
auto newGrandChildPairs =
489489
sliceChildShadowNodeViewPairsFromViewNodePair(newPair, innerScope);
490+
const size_t newGrandChildPairsSize = newGrandChildPairs.size();
490491
calculateShadowViewMutationsV2(
491492
innerScope,
492-
*(newGrandChildPairs.size()
493+
*(newGrandChildPairsSize != 0u
493494
? &mutationContainer.downwardMutations
494495
: &mutationContainer.destructiveDownwardMutations),
495496
oldPair.shadowView,
@@ -674,7 +675,8 @@ static void calculateShadowViewMutationsFlattener(
674675
? subVisitedNewMap->find(treeChildPair.shadowView.tag)
675676
: subVisitedNewMap->end());
676677
auto subVisitedOtherOldIt =
677-
(unvisitedIt == unvisitedOtherNodes.end() && subVisitedNewMap->end()
678+
(unvisitedIt == unvisitedOtherNodes.end() &&
679+
(subVisitedNewMap->end() != nullptr)
678680
? subVisitedOldMap->find(treeChildPair.shadowView.tag)
679681
: subVisitedOldMap->end());
680682

@@ -1123,9 +1125,10 @@ static void calculateShadowViewMutationsV2(
11231125
oldChildPair, innerScope);
11241126
auto newGrandChildPairs = sliceChildShadowNodeViewPairsFromViewNodePair(
11251127
newChildPair, innerScope);
1128+
const size_t newGrandChildPairsSize = newGrandChildPairs.size();
11261129
calculateShadowViewMutationsV2(
11271130
innerScope,
1128-
*(newGrandChildPairs.size()
1131+
*(newGrandChildPairsSize != 0u
11291132
? &mutationContainer.downwardMutations
11301133
: &mutationContainer.destructiveDownwardMutations),
11311134
oldChildPair.shadowView,

0 commit comments

Comments
 (0)