Skip to content

Commit f6a4f24

Browse files
generatedunixname89002005287564facebook-github-bot
authored andcommitted
Fix CQS signal readability-implicit-bool-conversion in xplat/js/react-native-github/packages [A] (#53612)
Summary: Pull Request resolved: #53612 Reviewed By: rshest Differential Revision: D81699159 fbshipit-source-id: b711e066b206d70ec40570b63dd1290d800e531f
1 parent 1be8527 commit f6a4f24

9 files changed

Lines changed: 46 additions & 44 deletions

File tree

packages/react-native/React/Inspector/RCTCxxInspectorPackagerConnectionDelegate.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
std::weak_ptr<IWebSocketDelegate> delegate)
3333
{
3434
auto *adapter = [[RCTCxxInspectorWebSocketAdapter alloc] initWithURL:url delegate:delegate];
35-
if (!adapter) {
35+
if (adapter == nullptr) {
3636
return nullptr;
3737
}
3838
return std::make_unique<WebSocket>(adapter);

packages/react-native/React/Inspector/RCTCxxInspectorWebSocketAdapter.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ @interface RCTCxxInspectorWebSocketAdapter () <SRWebSocketDelegate> {
3434
@implementation RCTCxxInspectorWebSocketAdapter
3535
- (instancetype)initWithURL:(const std::string &)url delegate:(std::weak_ptr<IWebSocketDelegate>)delegate
3636
{
37-
if ((self = [super init])) {
37+
if ((self = [super init]) != nullptr) {
3838
_delegate = delegate;
3939
_webSocket = [[SRWebSocket alloc] initWithURL:[NSURL URLWithString:NSStringFromUTF8StringView(url)]];
4040
_webSocket.delegate = self;
@@ -49,7 +49,7 @@ - (void)send:(std::string_view)message
4949
NSString *messageStr = NSStringFromUTF8StringView(message);
5050
dispatch_async(dispatch_get_main_queue(), ^{
5151
RCTCxxInspectorWebSocketAdapter *strongSelf = weakSelf;
52-
if (strongSelf) {
52+
if (strongSelf != nullptr) {
5353
[strongSelf->_webSocket sendString:messageStr error:NULL];
5454
}
5555
});

packages/react-native/React/Views/RCTComponentData.mm

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ - (instancetype)initWithManagerClass:(Class)managerClass
5050
bridge:(RCTBridge *)bridge
5151
eventDispatcher:(id<RCTEventDispatcherProtocol>)eventDispatcher
5252
{
53-
if ((self = [super init])) {
53+
if ((self = [super init]) != nullptr) {
5454
_bridge = bridge;
5555
_eventDispatcher = eventDispatcher;
5656
_managerClass = managerClass;
@@ -71,12 +71,12 @@ - (BOOL)isBridgeMode
7171

7272
- (RCTViewManager *)manager
7373
{
74-
if (!_manager && [self isBridgeMode]) {
74+
if ((_manager == nullptr) && [self isBridgeMode]) {
7575
_manager = [_bridge moduleForClass:_managerClass];
76-
} else if (!_manager && !_bridgelessViewManager) {
76+
} else if ((_manager == nullptr) && (_bridgelessViewManager == nullptr)) {
7777
_bridgelessViewManager = [_bridge moduleForClass:_managerClass];
7878
}
79-
return _manager ? _manager : _bridgelessViewManager;
79+
return (_manager != nullptr) ? _manager : _bridgelessViewManager;
8080
}
8181

8282
RCT_NOT_IMPLEMENTED(-(instancetype)init)
@@ -106,7 +106,7 @@ - (void)callCustomSetter:(SEL)setter onView:(id<RCTComponent>)view withProp:(id)
106106
{
107107
json = RCTNilIfNull(json);
108108
if (!isShadowView) {
109-
if (!json && !_defaultView) {
109+
if ((json == nullptr) && (_defaultView == nullptr)) {
110110
// Only create default view if json is null
111111
_defaultView = [self createViewWithTag:nil rootTag:nil];
112112
}
@@ -130,11 +130,11 @@ static RCTPropBlock createEventSetter(
130130
eventHandler = ^(NSDictionary *event) {
131131
// The component no longer exists, we shouldn't send the event
132132
id<RCTComponent> strongTarget = weakTarget;
133-
if (!strongTarget) {
133+
if (strongTarget == nullptr) {
134134
return;
135135
}
136136

137-
if (eventInterceptor) {
137+
if (eventInterceptor != nullptr) {
138138
eventInterceptor(propName, event, strongTarget.reactTag);
139139
} else {
140140
RCTComponentEvent *componentEvent = [[RCTComponentEvent alloc] initWithName:propName
@@ -158,13 +158,13 @@ static RCTPropBlock createNSInvocationSetter(NSMethodSignature *typeSignature, S
158158
__block NSMutableData *defaultValue = nil;
159159

160160
return ^(id target, id json) {
161-
if (!target) {
161+
if (target == nullptr) {
162162
return;
163163
}
164164

165165
// Get default value
166-
if (!defaultValue) {
167-
if (!json) {
166+
if (defaultValue == nullptr) {
167+
if (json == nullptr) {
168168
// We only set the defaultValue when we first pass a non-null
169169
// value, so if the first value sent for a prop is null, it's
170170
// a no-op (we'd be resetting it to its default when its
@@ -186,10 +186,10 @@ static RCTPropBlock createNSInvocationSetter(NSMethodSignature *typeSignature, S
186186
// Get value
187187
BOOL freeValueOnCompletion = NO;
188188
void *value = defaultValue.mutableBytes;
189-
if (json) {
189+
if (json != nullptr) {
190190
freeValueOnCompletion = YES;
191191
value = malloc(typeSignature.methodReturnLength);
192-
if (!value) {
192+
if (value == nullptr) {
193193
// CWE - 391 : Unchecked error condition
194194
// https://www.cvedetails.com/cwe-details/391/Unchecked-Error-Condition.html
195195
// https://eli.thegreenplace.net/2009/10/30/handling-out-of-memory-conditions-in-c
@@ -201,7 +201,7 @@ static RCTPropBlock createNSInvocationSetter(NSMethodSignature *typeSignature, S
201201
}
202202

203203
// Set value
204-
if (!targetInvocation) {
204+
if (targetInvocation == nullptr) {
205205
NSMethodSignature *signature = [target methodSignatureForSelector:setter];
206206
targetInvocation = [NSInvocation invocationWithMethodSignature:signature];
207207
targetInvocation.selector = setter;
@@ -252,7 +252,7 @@ - (RCTPropBlock)createPropBlock:(NSString *)name isShadowView:(BOOL)isShadowView
252252
// Disect keypath
253253
NSString *key = name;
254254
NSArray<NSString *> *parts = [keyPath componentsSeparatedByString:@"."];
255-
if (parts) {
255+
if (parts != nullptr) {
256256
key = parts.lastObject;
257257
parts = [parts subarrayWithRange:(NSRange){0, parts.count - 1}];
258258
}
@@ -275,7 +275,7 @@ - (RCTPropBlock)createPropBlock:(NSString *)name isShadowView:(BOOL)isShadowView
275275
} else {
276276
// Ordinary property handlers
277277
NSMethodSignature *typeSignature = [[RCTConvert class] methodSignatureForSelector:type];
278-
if (!typeSignature) {
278+
if (typeSignature == nullptr) {
279279
RCTLogError(@"No +[RCTConvert %@] function found.", NSStringFromSelector(type));
280280
return ^(__unused id<RCTComponent> view, __unused id json) {
281281
};
@@ -347,7 +347,7 @@ - (RCTPropBlock)propBlockForKey:(NSString *)name isShadowView:(BOOL)isShadowView
347347
{
348348
RCTPropBlockDictionary *propBlocks = isShadowView ? _shadowPropBlocks : _viewPropBlocks;
349349
RCTPropBlock propBlock = propBlocks[name];
350-
if (!propBlock) {
350+
if (propBlock == nullptr) {
351351
propBlock = [self createPropBlock:name isShadowView:isShadowView];
352352

353353
#if RCT_DEBUG
@@ -381,7 +381,7 @@ - (void)setProps:(NSDictionary<NSString *, id> *)props forShadowView:(RCTShadowV
381381

382382
- (void)setProps:(NSDictionary<NSString *, id> *)props forView:(id<RCTComponent>)view isShadowView:(BOOL)isShadowView
383383
{
384-
if (!view) {
384+
if (view == nullptr) {
385385
return;
386386
}
387387

@@ -467,13 +467,13 @@ - (void)setProps:(NSDictionary<NSString *, id> *)props forView:(id<RCTComponent>
467467

468468
// We need to handle both propConfig_* and propConfigShadow_* methods
469469
const char *underscorePos = strchr(selectorName + strlen("propConfig"), '_');
470-
if (!underscorePos) {
470+
if (underscorePos == nullptr) {
471471
continue;
472472
}
473473

474474
NSString *name = @(underscorePos + 1);
475475
NSString *type = ((NSArray<NSString *> * (*)(id, SEL)) objc_msgSend)(managerClass, selector)[0];
476-
if (RCT_DEBUG && propTypes[name] && ![propTypes[name] isEqualToString:type]) {
476+
if (RCT_DEBUG && (propTypes[name] != nullptr) && ![propTypes[name] isEqualToString:type]) {
477477
RCTLogError(
478478
@"Property '%@' of component '%@' redefined from '%@' "
479479
"to '%@'",

packages/react-native/ReactAndroid/src/main/jni/first-party/fbgloginit/glog_init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ lastResort(const char* tag, const char* msg, const char* arg = nullptr) {
102102
}
103103
#else
104104
std::cerr << msg;
105-
if (arg) {
105+
if (arg != nullptr) {
106106
std::cerr << ": " << arg;
107107
}
108108
std::cerr << std::endl;

packages/react-native/ReactAndroid/src/main/jni/react/devsupport/JInspectorNetworkReporter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ static std::unordered_map<int, std::string> responseBuffers;
6060

6161
/* static */ jboolean JInspectorNetworkReporter::isDebuggingEnabled(
6262
jni::alias_ref<jclass> /*unused*/) {
63-
return NetworkReporter::getInstance().isDebuggingEnabled();
63+
return static_cast<jboolean>(
64+
NetworkReporter::getInstance().isDebuggingEnabled());
6465
}
6566

6667
/* static */ void JInspectorNetworkReporter::reportRequestStart(
@@ -138,7 +139,7 @@ static std::unordered_map<int, std::string> responseBuffers;
138139
jint requestId,
139140
jboolean cancelled) {
140141
NetworkReporter::getInstance().reportRequestFailed(
141-
std::to_string(requestId), cancelled);
142+
std::to_string(requestId), cancelled != 0u);
142143
}
143144

144145
/* static */ void JInspectorNetworkReporter::maybeStoreResponseBodyImpl(

packages/react-native/ReactCommon/jsc/JSCRuntime.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ std::string JSStringToSTLString(JSStringRef str) {
320320
buffer = heapBuffer.get();
321321
}
322322
size_t actualBytes = JSStringGetUTF8CString(str, buffer, maxBytes);
323-
if (!actualBytes) {
323+
if (actualBytes == 0u) {
324324
// Happens if maxBytes == 0 (never the case here) or if str contains
325325
// invalid UTF-16 data, since JSStringGetUTF8CString attempts a strict
326326
// conversion.
@@ -437,7 +437,7 @@ jsi::Value JSCRuntime::evaluateJavaScript(
437437
JSValueRef res =
438438
JSEvaluateScript(ctx_, sourceRef, nullptr, sourceURLRef, 0, &exc);
439439
JSStringRelease(sourceRef);
440-
if (sourceURLRef) {
440+
if (sourceURLRef != nullptr) {
441441
JSStringRelease(sourceURLRef);
442442
}
443443
checkException(res, exc);
@@ -597,7 +597,7 @@ void JSCRuntime::JSCObjectValue::invalidate() noexcept {
597597

598598
jsi::Runtime::PointerValue* JSCRuntime::cloneSymbol(
599599
const jsi::Runtime::PointerValue* pv) {
600-
if (!pv) {
600+
if (pv == nullptr) {
601601
return nullptr;
602602
}
603603
const JSCSymbolValue* symbol = static_cast<const JSCSymbolValue*>(pv);
@@ -611,7 +611,7 @@ jsi::Runtime::PointerValue* JSCRuntime::cloneBigInt(
611611

612612
jsi::Runtime::PointerValue* JSCRuntime::cloneString(
613613
const jsi::Runtime::PointerValue* pv) {
614-
if (!pv) {
614+
if (pv == nullptr) {
615615
return nullptr;
616616
}
617617
const JSCStringValue* string = static_cast<const JSCStringValue*>(pv);
@@ -620,7 +620,7 @@ jsi::Runtime::PointerValue* JSCRuntime::cloneString(
620620

621621
jsi::Runtime::PointerValue* JSCRuntime::cloneObject(
622622
const jsi::Runtime::PointerValue* pv) {
623-
if (!pv) {
623+
if (pv == nullptr) {
624624
return nullptr;
625625
}
626626
const JSCObjectValue* object = static_cast<const JSCObjectValue*>(pv);
@@ -632,7 +632,7 @@ jsi::Runtime::PointerValue* JSCRuntime::cloneObject(
632632

633633
jsi::Runtime::PointerValue* JSCRuntime::clonePropNameID(
634634
const jsi::Runtime::PointerValue* pv) {
635-
if (!pv) {
635+
if (pv == nullptr) {
636636
return nullptr;
637637
}
638638
const JSCStringValue* string = static_cast<const JSCStringValue*>(pv);
@@ -914,7 +914,7 @@ JSClassRef getNativeStateClass() {
914914
} // namespace
915915

916916
JSValueRef JSCRuntime::getNativeStateSymbol() {
917-
if (!nativeStateSymbol_) {
917+
if (nativeStateSymbol_ == nullptr) {
918918
JSStringRef symbolName =
919919
JSStringCreateWithUTF8CString("__internal_nativeState");
920920
JSValueRef symbol = JSValueMakeSymbol(ctx_, symbolName);
@@ -1182,7 +1182,7 @@ jsi::Function JSCRuntime::createFunctionFromHostFunction(
11821182
kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum |
11831183
kJSPropertyAttributeDontDelete,
11841184
&exc);
1185-
if (exc) {
1185+
if (exc != nullptr) {
11861186
// Silently fail to set length
11871187
exc = nullptr;
11881188
}
@@ -1198,7 +1198,7 @@ jsi::Function JSCRuntime::createFunctionFromHostFunction(
11981198
kJSPropertyAttributeDontDelete,
11991199
&exc);
12001200
JSStringRelease(name);
1201-
if (exc) {
1201+
if (exc != nullptr) {
12021202
// Silently fail to set name
12031203
exc = nullptr;
12041204
}
@@ -1211,7 +1211,7 @@ jsi::Function JSCRuntime::createFunctionFromHostFunction(
12111211
abort();
12121212
}
12131213
JSObjectRef funcCtor = JSValueToObject(ctx, value, &exc);
1214-
if (!funcCtor) {
1214+
if (funcCtor == nullptr) {
12151215
// We can't do anything if Function is not an object
12161216
return;
12171217
}
@@ -1439,7 +1439,7 @@ JSStringRef getEmptyString() {
14391439

14401440
jsi::Runtime::PointerValue* JSCRuntime::makeStringValue(
14411441
JSStringRef stringRef) const {
1442-
if (!stringRef) {
1442+
if (stringRef == nullptr) {
14431443
stringRef = getEmptyString();
14441444
}
14451445
#ifndef NDEBUG
@@ -1463,7 +1463,7 @@ jsi::PropNameID JSCRuntime::createPropNameID(JSStringRef str) {
14631463

14641464
jsi::Runtime::PointerValue* JSCRuntime::makeObjectValue(
14651465
JSObjectRef objectRef) const {
1466-
if (!objectRef) {
1466+
if (objectRef == nullptr) {
14671467
objectRef = JSObjectMake(ctx_, nullptr, nullptr);
14681468
}
14691469
#ifndef NDEBUG

packages/react-native/ReactCommon/jsinspector-modern/tests/InspectorPackagerConnectionTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class InspectorPackagerConnectionTestBase : public testing::Test {
5959
auto pages = getInspectorInstance().getPages();
6060
int liveConnectionCount = 0;
6161
for (size_t i = 0; i != localConnections_.objectsVended(); ++i) {
62-
if (localConnections_[i]) {
62+
if (localConnections_[i] != nullptr) {
6363
liveConnectionCount++;
6464
// localConnections_[i] is a strict mock and will complain when we
6565
// removePage if the call is unexpected.
@@ -69,7 +69,7 @@ class InspectorPackagerConnectionTestBase : public testing::Test {
6969
for (auto& page : pages) {
7070
getInspectorInstance().removePage(page.id);
7171
}
72-
if (!pages.empty() && liveConnectionCount) {
72+
if (!pages.empty() && (liveConnectionCount != 0)) {
7373
if (!::testing::Test::HasFailure()) {
7474
FAIL()
7575
<< "Test case ended with " << liveConnectionCount

packages/react-native/ReactCommon/jsinspector-modern/tests/JsiIntegrationTest.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ class JsiIntegrationPortableTestBase : public ::testing::Test,
6565

6666
~JsiIntegrationPortableTestBase() override {
6767
toPage_.reset();
68-
if (runtimeTarget_) {
68+
if (runtimeTarget_ != nullptr) {
6969
EXPECT_TRUE(instance_);
7070
instance_->unregisterRuntime(*runtimeTarget_);
7171
runtimeTarget_ = nullptr;
7272
}
73-
if (instance_) {
73+
if (instance_ != nullptr) {
7474
page_->unregisterInstance(*instance_);
7575
instance_ = nullptr;
7676
}
@@ -108,12 +108,12 @@ class JsiIntegrationPortableTestBase : public ::testing::Test,
108108
}
109109

110110
void reload() {
111-
if (runtimeTarget_) {
111+
if (runtimeTarget_ != nullptr) {
112112
ASSERT_TRUE(instance_);
113113
instance_->unregisterRuntime(*runtimeTarget_);
114114
runtimeTarget_ = nullptr;
115115
}
116-
if (instance_) {
116+
if (instance_ != nullptr) {
117117
page_->unregisterInstance(*instance_);
118118
instance_ = nullptr;
119119
}

packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,8 @@ JNIArgs convertJSIArgsToJNIArgs(
395395
"boolean", argIndex, methodName, arg, &rt);
396396
}
397397
jarg->l = makeGlobalIfNecessary(
398-
jni::JBoolean::valueOf(arg->getBool()).release());
398+
jni::JBoolean::valueOf(static_cast<unsigned char>(arg->getBool()))
399+
.release());
399400
} else if (type == "Ljava/lang/String;") {
400401
if (!arg->isString()) {
401402
throw JavaTurboModuleArgumentConversionException(

0 commit comments

Comments
 (0)