From 2e24197da348ff89325d81857be5adb87dc2fcf6 Mon Sep 17 00:00:00 2001 From: Georgiy Kassabli Date: Tue, 23 May 2017 11:11:37 -0700 Subject: [PATCH] Fixing potential measure call with negative size value Reviewed By: emilsjolander Differential Revision: D5111534 fbshipit-source-id: 99f09b85f0c6a0e5dec89a26baba8f9d560100da --- ReactCommon/yoga/yoga/Yoga.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ReactCommon/yoga/yoga/Yoga.c b/ReactCommon/yoga/yoga/Yoga.c index 9aaa6333e..e77a9ca6d 100644 --- a/ReactCommon/yoga/yoga/Yoga.c +++ b/ReactCommon/yoga/yoga/Yoga.c @@ -1736,8 +1736,13 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions(const YGNodeRef node, const float marginAxisRow = YGNodeMarginForAxis(node, YGFlexDirectionRow, availableWidth); const float marginAxisColumn = YGNodeMarginForAxis(node, YGFlexDirectionColumn, availableWidth); - const float innerWidth = availableWidth - marginAxisRow - paddingAndBorderAxisRow; - const float innerHeight = availableHeight - marginAxisColumn - paddingAndBorderAxisColumn; + // We want to make sure we don't call measure with negative size + const float innerWidth = YGFloatIsUndefined(availableWidth) + ? availableWidth + : fmaxf(0, availableWidth - marginAxisRow - paddingAndBorderAxisRow); + const float innerHeight = YGFloatIsUndefined(availableHeight) + ? availableHeight + : fmaxf(0, availableHeight - marginAxisColumn - paddingAndBorderAxisColumn); if (widthMeasureMode == YGMeasureModeExactly && heightMeasureMode == YGMeasureModeExactly) { // Don't bother sizing the text if both dimensions are already defined.