Skip to content

Commit

Permalink
Fix RCTNullIfNil macro
Browse files Browse the repository at this point in the history
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
Peter Argany authored and facebook-github-bot committed Oct 16, 2019
1 parent 474f12e commit 79b5735
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion React/Base/RCTUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; })

Expand Down

0 comments on commit 79b5735

Please sign in to comment.