Skip to content

Commit

Permalink
Fix warnings around mixing int and size_t usage in unsafe ways (faceb…
Browse files Browse the repository at this point in the history
…ook#34889)

Summary:
react-native-windows builds treat a lot of c++ compiler warnings as errors.  Including ones that cause value truncation when assigning `size_t` values to an `int`.

This fixes the compiler warning, by using `size_t` as the type for `i`, which matches `size`.  I then modified the loop to avoid the value underflow that occurs when decrementing an unsigned zero value.

## Changelog
[Internal] [Changed] - Fix compiler warnings around mixing int and size_t usage in unsafe ways

Pull Request resolved: facebook#34889

Test Plan: This code change was made in react-native-windows when integrating latest react-native changes.  -- our fabric implementation was able to run through this code without any issues.

Reviewed By: mdvacca

Differential Revision: D40158306

Pulled By: rozele

fbshipit-source-id: b6858cb953635b37fd63a88ed1a372eb3dc394f7
  • Loading branch information
acoates-ms authored and facebook-github-bot committed Oct 6, 2022
1 parent 9a44e5b commit 138c88c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions ReactCommon/react/renderer/core/LayoutableShadowNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,31 @@ static LayoutableSmallVector<Rect> calculateTransformedFrames(
auto transformedFrames = LayoutableSmallVector<Rect>{size};
auto transformation = Transform::Identity();

for (int i = size - 1; i >= 0; --i) {
for (auto i = size; i > 0; --i) {
auto currentShadowNode =
traitCast<LayoutableShadowNode const *>(shadowNodeList.at(i));
traitCast<LayoutableShadowNode const *>(shadowNodeList.at(i - 1));
auto currentFrame = currentShadowNode->getLayoutMetrics().frame;

if (policy.includeTransform) {
if (Transform::isVerticalInversion(transformation)) {
auto parentShadowNode =
traitCast<LayoutableShadowNode const *>(shadowNodeList.at(i + 1));
traitCast<LayoutableShadowNode const *>(shadowNodeList.at(i));
currentFrame.origin.y =
parentShadowNode->getLayoutMetrics().frame.size.height -
currentFrame.size.height - currentFrame.origin.y;
}

if (Transform::isHorizontalInversion(transformation)) {
auto parentShadowNode =
traitCast<LayoutableShadowNode const *>(shadowNodeList.at(i + 1));
traitCast<LayoutableShadowNode const *>(shadowNodeList.at(i));
currentFrame.origin.x =
parentShadowNode->getLayoutMetrics().frame.size.width -
currentFrame.size.width - currentFrame.origin.x;
}

if (i != size - 1) {
if (i != size) {
auto parentShadowNode =
traitCast<LayoutableShadowNode const *>(shadowNodeList.at(i + 1));
traitCast<LayoutableShadowNode const *>(shadowNodeList.at(i));
auto contentOritinOffset = parentShadowNode->getContentOriginOffset();
if (Transform::isVerticalInversion(transformation)) {
contentOritinOffset.y = -contentOritinOffset.y;
Expand All @@ -65,7 +65,7 @@ static LayoutableSmallVector<Rect> calculateTransformedFrames(
transformation = transformation * currentShadowNode->getTransform();
}

transformedFrames[i] = currentFrame;
transformedFrames[i - 1] = currentFrame;
}

return transformedFrames;
Expand Down

0 comments on commit 138c88c

Please sign in to comment.