From dc6ed89bfafb472a1c684ce6b3f1872a85c2dad1 Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Tue, 9 Jan 2018 04:21:58 -0800 Subject: [PATCH] Fix warnings of casting and null pointer handling Summary: There were warnings of castings and null pointer handling in yoga.cpp. This diff fixes the warnings. The issue was brought up here https://github.com/facebook/react-native/issues/17274 Reviewed By: emilsjolander Differential Revision: D6675111 fbshipit-source-id: 884659fabb05033b4d43d3aa6629e22481d39b7e --- yoga/YGNode.cpp | 2 +- yoga/YGNodePrint.cpp | 2 +- yoga/Yoga.cpp | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/yoga/YGNode.cpp b/yoga/YGNode.cpp index 5099a246..f5f66c7c 100644 --- a/yoga/YGNode.cpp +++ b/yoga/YGNode.cpp @@ -385,7 +385,7 @@ void YGNode::cloneChildrenIfNeeded() { // YGNodeRemoveChild in yoga.cpp has a forked variant of this algorithm // optimized for deletions. - const uint32_t childCount = children_.size(); + const uint32_t childCount = static_cast(children_.size()); if (childCount == 0) { // This is an empty set. Nothing to clone. return; diff --git a/yoga/YGNodePrint.cpp b/yoga/YGNodePrint.cpp index e49903ac..0951e955 100644 --- a/yoga/YGNodePrint.cpp +++ b/yoga/YGNodePrint.cpp @@ -212,7 +212,7 @@ void YGNodeToString( } appendFormatedString(str, ">"); - const uint32_t childCount = node->getChildren().size(); + const uint32_t childCount = static_cast(node->getChildren().size()); if (options & YGPrintOptionsChildren && childCount > 0) { for (uint32_t i = 0; i < childCount; i++) { appendFormatedString(str, "\n"); diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 186c6ce4..f4bae13d 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -321,7 +321,9 @@ YGConfigRef YGConfigGetDefault() { YGConfigRef YGConfigNew(void) { const YGConfigRef config = (const YGConfigRef)malloc(sizeof(YGConfig)); YGAssert(config != nullptr, "Could not allocate memory for config"); - + if (config == nullptr) { + abort(); + } gConfigInstanceCount++; memcpy(config, &gYGConfigDefaults, sizeof(YGConfig)); return config; @@ -433,7 +435,7 @@ YGNodeRef YGNodeGetChild(const YGNodeRef node, const uint32_t index) { } uint32_t YGNodeGetChildCount(const YGNodeRef node) { - return node->getChildren().size(); + return static_cast(node->getChildren().size()); } YGNodeRef YGNodeGetParent(const YGNodeRef node) { @@ -1895,7 +1897,7 @@ static void YGNodelayoutImpl(const YGNodeRef node, return; } - const uint32_t childCount = node->getChildren().size(); + const uint32_t childCount = YGNodeGetChildCount(node); if (childCount == 0) { YGNodeEmptyContainerSetMeasuredDimensions(node, availableWidth, @@ -3556,7 +3558,7 @@ static void YGRoundToPixelGrid(const YGNodeRef node, absoluteNodeTop, pointScaleFactor, false, textRounding), YGDimensionHeight); - const uint32_t childCount = node->getChildren().size(); + const uint32_t childCount = YGNodeGetChildCount(node); for (uint32_t i = 0; i < childCount; i++) { YGRoundToPixelGrid(YGNodeGetChild(node, i), pointScaleFactor, absoluteNodeLeft, absoluteNodeTop); }