Fix warnings of casting and null pointer handling

Reviewed By: emilsjolander

Differential Revision: D6675111

fbshipit-source-id: 884659fabb05033b4d43d3aa6629e22481d39b7e
This commit is contained in:
Pritesh Nandgaonkar 2018-01-09 04:21:58 -08:00 committed by Facebook Github Bot
parent 11a495cb32
commit a8d4666651
3 changed files with 8 additions and 6 deletions

View File

@ -385,7 +385,7 @@ void YGNode::cloneChildrenIfNeeded() {
// YGNodeRemoveChild in yoga.cpp has a forked variant of this algorithm // YGNodeRemoveChild in yoga.cpp has a forked variant of this algorithm
// optimized for deletions. // optimized for deletions.
const uint32_t childCount = children_.size(); const uint32_t childCount = static_cast<uint32_t>(children_.size());
if (childCount == 0) { if (childCount == 0) {
// This is an empty set. Nothing to clone. // This is an empty set. Nothing to clone.
return; return;

View File

@ -212,7 +212,7 @@ void YGNodeToString(
} }
appendFormatedString(str, ">"); appendFormatedString(str, ">");
const uint32_t childCount = node->getChildren().size(); const uint32_t childCount = static_cast<uint32_t>(node->getChildren().size());
if (options & YGPrintOptionsChildren && childCount > 0) { if (options & YGPrintOptionsChildren && childCount > 0) {
for (uint32_t i = 0; i < childCount; i++) { for (uint32_t i = 0; i < childCount; i++) {
appendFormatedString(str, "\n"); appendFormatedString(str, "\n");

View File

@ -321,7 +321,9 @@ YGConfigRef YGConfigGetDefault() {
YGConfigRef YGConfigNew(void) { YGConfigRef YGConfigNew(void) {
const YGConfigRef config = (const YGConfigRef)malloc(sizeof(YGConfig)); const YGConfigRef config = (const YGConfigRef)malloc(sizeof(YGConfig));
YGAssert(config != nullptr, "Could not allocate memory for config"); YGAssert(config != nullptr, "Could not allocate memory for config");
if (config == nullptr) {
abort();
}
gConfigInstanceCount++; gConfigInstanceCount++;
memcpy(config, &gYGConfigDefaults, sizeof(YGConfig)); memcpy(config, &gYGConfigDefaults, sizeof(YGConfig));
return config; return config;
@ -433,7 +435,7 @@ YGNodeRef YGNodeGetChild(const YGNodeRef node, const uint32_t index) {
} }
uint32_t YGNodeGetChildCount(const YGNodeRef node) { uint32_t YGNodeGetChildCount(const YGNodeRef node) {
return node->getChildren().size(); return static_cast<uint32_t>(node->getChildren().size());
} }
YGNodeRef YGNodeGetParent(const YGNodeRef node) { YGNodeRef YGNodeGetParent(const YGNodeRef node) {
@ -1895,7 +1897,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
return; return;
} }
const uint32_t childCount = node->getChildren().size(); const uint32_t childCount = YGNodeGetChildCount(node);
if (childCount == 0) { if (childCount == 0) {
YGNodeEmptyContainerSetMeasuredDimensions(node, YGNodeEmptyContainerSetMeasuredDimensions(node,
availableWidth, availableWidth,
@ -3556,7 +3558,7 @@ static void YGRoundToPixelGrid(const YGNodeRef node,
absoluteNodeTop, pointScaleFactor, false, textRounding), absoluteNodeTop, pointScaleFactor, false, textRounding),
YGDimensionHeight); YGDimensionHeight);
const uint32_t childCount = node->getChildren().size(); const uint32_t childCount = YGNodeGetChildCount(node);
for (uint32_t i = 0; i < childCount; i++) { for (uint32_t i = 0; i < childCount; i++) {
YGRoundToPixelGrid(YGNodeGetChild(node, i), pointScaleFactor, absoluteNodeLeft, absoluteNodeTop); YGRoundToPixelGrid(YGNodeGetChild(node, i), pointScaleFactor, absoluteNodeLeft, absoluteNodeTop);
} }