From 920bd2c199be6838aa0d106590a899b327f750d3 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Fri, 25 Sep 2020 17:25:58 -0700 Subject: [PATCH] Fabric: Fixed crash in `colorComponentsFromColor()` Summary: This fixes a recently introduced crash in `colorComponentsFromColor()` (iOS implementation) caused by dereferencing a null pointer. The fix is just a copy of a code fragment from a previous implementation. Reviewed By: fkgozali Differential Revision: D23944812 fbshipit-source-id: 977135dd75c4375affddfd75183e4890618ae819 --- ReactCommon/react/renderer/graphics/platform/ios/Color.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ReactCommon/react/renderer/graphics/platform/ios/Color.cpp b/ReactCommon/react/renderer/graphics/platform/ios/Color.cpp index 0b114759cb1aa0..c1023384cac7bd 100644 --- a/ReactCommon/react/renderer/graphics/platform/ios/Color.cpp +++ b/ReactCommon/react/renderer/graphics/platform/ios/Color.cpp @@ -21,6 +21,12 @@ SharedColor colorFromComponents(ColorComponents components) { } ColorComponents colorComponentsFromColor(SharedColor sharedColor) { + if (!sharedColor) { + // Empty color object can be considered as `clear` (black, fully + // transparent) color. + return ColorComponents{0, 0, 0, 0}; + } + float ratio = 256; Color color = *sharedColor; return ColorComponents{(float)((color >> 16) & 0xff) / ratio,