From 79b573511bd55e6c82c0044e1930549ccfa8a923 Mon Sep 17 00:00:00 2001 From: Peter Argany Date: Tue, 15 Oct 2019 18:00:39 -0700 Subject: [PATCH] Fix RCTNullIfNil macro Summary: `RCTNullIfNil()` can return nil in certain scenarios. Example, given: `#define RCTNullIfNil(value) (value ?: (id)kCFNull)` `RCTNullIfNil(nil == nil ? nil : @"lol")` expanded out `nil == nil ? nil : @"lol" ?: (id)kCFNull` `?:` takes precedence, so reduced: `nil == nil ? nil : @"lol"` `nil` Changelog: [iOS] [Fixed] Fixed longstanding bug where RCTNullIfNil() can return nil Reviewed By: RSNara Differential Revision: D17943530 fbshipit-source-id: 8c6e3dd2d86cbc8ff1fcbef732674835a312ef26 --- React/Base/RCTUtils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/React/Base/RCTUtils.h b/React/Base/RCTUtils.h index 6c882a7223d04c..fc491fd70f53a4 100644 --- a/React/Base/RCTUtils.h +++ b/React/Base/RCTUtils.h @@ -93,7 +93,7 @@ RCT_EXTERN BOOL RCTForceTouchAvailable(void); RCT_EXTERN NSError *RCTErrorWithMessage(NSString *message); // Convert nil values to NSNull, and vice-versa -#define RCTNullIfNil(value) (value ?: (id)kCFNull) +#define RCTNullIfNil(value) ((value) ?: (id)kCFNull) #define RCTNilIfNull(value) \ ({ __typeof__(value) t = (value); (id)t == (id)kCFNull ? (__typeof(value))nil : t; })