Skip to content
Permalink
Browse files
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
  • Loading branch information
PeteTheHeat authored and facebook-github-bot committed Oct 16, 2019
1 parent 474f12e commit 79b573511bd55e6c82c0044e1930549ccfa8a923
Showing 1 changed file with 1 addition and 1 deletion.
@@ -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; })

0 comments on commit 79b5735

Please sign in to comment.