From f6a4f24090bca96be5e5e0cb082ca1068aa905ff Mon Sep 17 00:00:00 2001 From: generatedunixname89002005287564 Date: Fri, 5 Sep 2025 03:05:35 -0700 Subject: [PATCH] Fix CQS signal readability-implicit-bool-conversion in xplat/js/react-native-github/packages [A] (#53612) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53612 Reviewed By: rshest Differential Revision: D81699159 fbshipit-source-id: b711e066b206d70ec40570b63dd1290d800e531f --- ...TCxxInspectorPackagerConnectionDelegate.mm | 2 +- .../RCTCxxInspectorWebSocketAdapter.mm | 4 +- .../React/Views/RCTComponentData.mm | 38 +++++++++---------- .../jni/first-party/fbgloginit/glog_init.cpp | 2 +- .../devsupport/JInspectorNetworkReporter.cpp | 5 ++- .../ReactCommon/jsc/JSCRuntime.cpp | 24 ++++++------ .../tests/InspectorPackagerConnectionTest.cpp | 4 +- .../tests/JsiIntegrationTest.h | 8 ++-- .../android/ReactCommon/JavaTurboModule.cpp | 3 +- 9 files changed, 46 insertions(+), 44 deletions(-) diff --git a/packages/react-native/React/Inspector/RCTCxxInspectorPackagerConnectionDelegate.mm b/packages/react-native/React/Inspector/RCTCxxInspectorPackagerConnectionDelegate.mm index b7bf705b289..c85bd4d3aa4 100644 --- a/packages/react-native/React/Inspector/RCTCxxInspectorPackagerConnectionDelegate.mm +++ b/packages/react-native/React/Inspector/RCTCxxInspectorPackagerConnectionDelegate.mm @@ -32,7 +32,7 @@ std::unique_ptr RCTCxxInspectorPackagerConnectionDelegate::connectWe std::weak_ptr delegate) { auto *adapter = [[RCTCxxInspectorWebSocketAdapter alloc] initWithURL:url delegate:delegate]; - if (!adapter) { + if (adapter == nullptr) { return nullptr; } return std::make_unique(adapter); diff --git a/packages/react-native/React/Inspector/RCTCxxInspectorWebSocketAdapter.mm b/packages/react-native/React/Inspector/RCTCxxInspectorWebSocketAdapter.mm index 9ab428fe398..4b0754b26ae 100644 --- a/packages/react-native/React/Inspector/RCTCxxInspectorWebSocketAdapter.mm +++ b/packages/react-native/React/Inspector/RCTCxxInspectorWebSocketAdapter.mm @@ -34,7 +34,7 @@ NSString *NSStringFromUTF8StringView(std::string_view view) @implementation RCTCxxInspectorWebSocketAdapter - (instancetype)initWithURL:(const std::string &)url delegate:(std::weak_ptr)delegate { - if ((self = [super init])) { + if ((self = [super init]) != nullptr) { _delegate = delegate; _webSocket = [[SRWebSocket alloc] initWithURL:[NSURL URLWithString:NSStringFromUTF8StringView(url)]]; _webSocket.delegate = self; @@ -49,7 +49,7 @@ NSString *NSStringFromUTF8StringView(std::string_view view) NSString *messageStr = NSStringFromUTF8StringView(message); dispatch_async(dispatch_get_main_queue(), ^{ RCTCxxInspectorWebSocketAdapter *strongSelf = weakSelf; - if (strongSelf) { + if (strongSelf != nullptr) { [strongSelf->_webSocket sendString:messageStr error:NULL]; } }); diff --git a/packages/react-native/React/Views/RCTComponentData.mm b/packages/react-native/React/Views/RCTComponentData.mm index 5e39f77c86c..36de415c2b4 100644 --- a/packages/react-native/React/Views/RCTComponentData.mm +++ b/packages/react-native/React/Views/RCTComponentData.mm @@ -50,7 +50,7 @@ static SEL selectorForType(NSString *type) bridge:(RCTBridge *)bridge eventDispatcher:(id)eventDispatcher { - if ((self = [super init])) { + if ((self = [super init]) != nullptr) { _bridge = bridge; _eventDispatcher = eventDispatcher; _managerClass = managerClass; @@ -71,12 +71,12 @@ static SEL selectorForType(NSString *type) - (RCTViewManager *)manager { - if (!_manager && [self isBridgeMode]) { + if ((_manager == nullptr) && [self isBridgeMode]) { _manager = [_bridge moduleForClass:_managerClass]; - } else if (!_manager && !_bridgelessViewManager) { + } else if ((_manager == nullptr) && (_bridgelessViewManager == nullptr)) { _bridgelessViewManager = [_bridge moduleForClass:_managerClass]; } - return _manager ? _manager : _bridgelessViewManager; + return (_manager != nullptr) ? _manager : _bridgelessViewManager; } RCT_NOT_IMPLEMENTED(-(instancetype)init) @@ -106,7 +106,7 @@ RCT_NOT_IMPLEMENTED(-(instancetype)init) { json = RCTNilIfNull(json); if (!isShadowView) { - if (!json && !_defaultView) { + if ((json == nullptr) && (_defaultView == nullptr)) { // Only create default view if json is null _defaultView = [self createViewWithTag:nil rootTag:nil]; } @@ -130,11 +130,11 @@ static RCTPropBlock createEventSetter( eventHandler = ^(NSDictionary *event) { // The component no longer exists, we shouldn't send the event id strongTarget = weakTarget; - if (!strongTarget) { + if (strongTarget == nullptr) { return; } - if (eventInterceptor) { + if (eventInterceptor != nullptr) { eventInterceptor(propName, event, strongTarget.reactTag); } else { RCTComponentEvent *componentEvent = [[RCTComponentEvent alloc] initWithName:propName @@ -158,13 +158,13 @@ static RCTPropBlock createNSInvocationSetter(NSMethodSignature *typeSignature, S __block NSMutableData *defaultValue = nil; return ^(id target, id json) { - if (!target) { + if (target == nullptr) { return; } // Get default value - if (!defaultValue) { - if (!json) { + if (defaultValue == nullptr) { + if (json == nullptr) { // We only set the defaultValue when we first pass a non-null // value, so if the first value sent for a prop is null, it's // a no-op (we'd be resetting it to its default when its @@ -186,10 +186,10 @@ static RCTPropBlock createNSInvocationSetter(NSMethodSignature *typeSignature, S // Get value BOOL freeValueOnCompletion = NO; void *value = defaultValue.mutableBytes; - if (json) { + if (json != nullptr) { freeValueOnCompletion = YES; value = malloc(typeSignature.methodReturnLength); - if (!value) { + if (value == nullptr) { // CWE - 391 : Unchecked error condition // https://www.cvedetails.com/cwe-details/391/Unchecked-Error-Condition.html // https://eli.thegreenplace.net/2009/10/30/handling-out-of-memory-conditions-in-c @@ -201,7 +201,7 @@ static RCTPropBlock createNSInvocationSetter(NSMethodSignature *typeSignature, S } // Set value - if (!targetInvocation) { + if (targetInvocation == nullptr) { NSMethodSignature *signature = [target methodSignatureForSelector:setter]; targetInvocation = [NSInvocation invocationWithMethodSignature:signature]; targetInvocation.selector = setter; @@ -252,7 +252,7 @@ static RCTPropBlock createNSInvocationSetter(NSMethodSignature *typeSignature, S // Disect keypath NSString *key = name; NSArray *parts = [keyPath componentsSeparatedByString:@"."]; - if (parts) { + if (parts != nullptr) { key = parts.lastObject; parts = [parts subarrayWithRange:(NSRange){0, parts.count - 1}]; } @@ -275,7 +275,7 @@ static RCTPropBlock createNSInvocationSetter(NSMethodSignature *typeSignature, S } else { // Ordinary property handlers NSMethodSignature *typeSignature = [[RCTConvert class] methodSignatureForSelector:type]; - if (!typeSignature) { + if (typeSignature == nullptr) { RCTLogError(@"No +[RCTConvert %@] function found.", NSStringFromSelector(type)); return ^(__unused id view, __unused id json) { }; @@ -347,7 +347,7 @@ static RCTPropBlock createNSInvocationSetter(NSMethodSignature *typeSignature, S { RCTPropBlockDictionary *propBlocks = isShadowView ? _shadowPropBlocks : _viewPropBlocks; RCTPropBlock propBlock = propBlocks[name]; - if (!propBlock) { + if (propBlock == nullptr) { propBlock = [self createPropBlock:name isShadowView:isShadowView]; #if RCT_DEBUG @@ -381,7 +381,7 @@ static RCTPropBlock createNSInvocationSetter(NSMethodSignature *typeSignature, S - (void)setProps:(NSDictionary *)props forView:(id)view isShadowView:(BOOL)isShadowView { - if (!view) { + if (view == nullptr) { return; } @@ -467,13 +467,13 @@ static RCTPropBlock createNSInvocationSetter(NSMethodSignature *typeSignature, S // We need to handle both propConfig_* and propConfigShadow_* methods const char *underscorePos = strchr(selectorName + strlen("propConfig"), '_'); - if (!underscorePos) { + if (underscorePos == nullptr) { continue; } NSString *name = @(underscorePos + 1); NSString *type = ((NSArray * (*)(id, SEL)) objc_msgSend)(managerClass, selector)[0]; - if (RCT_DEBUG && propTypes[name] && ![propTypes[name] isEqualToString:type]) { + if (RCT_DEBUG && (propTypes[name] != nullptr) && ![propTypes[name] isEqualToString:type]) { RCTLogError( @"Property '%@' of component '%@' redefined from '%@' " "to '%@'", diff --git a/packages/react-native/ReactAndroid/src/main/jni/first-party/fbgloginit/glog_init.cpp b/packages/react-native/ReactAndroid/src/main/jni/first-party/fbgloginit/glog_init.cpp index dac26d8d0c0..c7174b83227 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/first-party/fbgloginit/glog_init.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/first-party/fbgloginit/glog_init.cpp @@ -102,7 +102,7 @@ lastResort(const char* tag, const char* msg, const char* arg = nullptr) { } #else std::cerr << msg; - if (arg) { + if (arg != nullptr) { std::cerr << ": " << arg; } std::cerr << std::endl; diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/devsupport/JInspectorNetworkReporter.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/devsupport/JInspectorNetworkReporter.cpp index 41e25e3c85c..34eda93de81 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/devsupport/JInspectorNetworkReporter.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/devsupport/JInspectorNetworkReporter.cpp @@ -60,7 +60,8 @@ static std::unordered_map responseBuffers; /* static */ jboolean JInspectorNetworkReporter::isDebuggingEnabled( jni::alias_ref /*unused*/) { - return NetworkReporter::getInstance().isDebuggingEnabled(); + return static_cast( + NetworkReporter::getInstance().isDebuggingEnabled()); } /* static */ void JInspectorNetworkReporter::reportRequestStart( @@ -138,7 +139,7 @@ static std::unordered_map responseBuffers; jint requestId, jboolean cancelled) { NetworkReporter::getInstance().reportRequestFailed( - std::to_string(requestId), cancelled); + std::to_string(requestId), cancelled != 0u); } /* static */ void JInspectorNetworkReporter::maybeStoreResponseBodyImpl( diff --git a/packages/react-native/ReactCommon/jsc/JSCRuntime.cpp b/packages/react-native/ReactCommon/jsc/JSCRuntime.cpp index 46528bad745..3d14d45a70b 100644 --- a/packages/react-native/ReactCommon/jsc/JSCRuntime.cpp +++ b/packages/react-native/ReactCommon/jsc/JSCRuntime.cpp @@ -320,7 +320,7 @@ std::string JSStringToSTLString(JSStringRef str) { buffer = heapBuffer.get(); } size_t actualBytes = JSStringGetUTF8CString(str, buffer, maxBytes); - if (!actualBytes) { + if (actualBytes == 0u) { // Happens if maxBytes == 0 (never the case here) or if str contains // invalid UTF-16 data, since JSStringGetUTF8CString attempts a strict // conversion. @@ -437,7 +437,7 @@ jsi::Value JSCRuntime::evaluateJavaScript( JSValueRef res = JSEvaluateScript(ctx_, sourceRef, nullptr, sourceURLRef, 0, &exc); JSStringRelease(sourceRef); - if (sourceURLRef) { + if (sourceURLRef != nullptr) { JSStringRelease(sourceURLRef); } checkException(res, exc); @@ -597,7 +597,7 @@ void JSCRuntime::JSCObjectValue::invalidate() noexcept { jsi::Runtime::PointerValue* JSCRuntime::cloneSymbol( const jsi::Runtime::PointerValue* pv) { - if (!pv) { + if (pv == nullptr) { return nullptr; } const JSCSymbolValue* symbol = static_cast(pv); @@ -611,7 +611,7 @@ jsi::Runtime::PointerValue* JSCRuntime::cloneBigInt( jsi::Runtime::PointerValue* JSCRuntime::cloneString( const jsi::Runtime::PointerValue* pv) { - if (!pv) { + if (pv == nullptr) { return nullptr; } const JSCStringValue* string = static_cast(pv); @@ -620,7 +620,7 @@ jsi::Runtime::PointerValue* JSCRuntime::cloneString( jsi::Runtime::PointerValue* JSCRuntime::cloneObject( const jsi::Runtime::PointerValue* pv) { - if (!pv) { + if (pv == nullptr) { return nullptr; } const JSCObjectValue* object = static_cast(pv); @@ -632,7 +632,7 @@ jsi::Runtime::PointerValue* JSCRuntime::cloneObject( jsi::Runtime::PointerValue* JSCRuntime::clonePropNameID( const jsi::Runtime::PointerValue* pv) { - if (!pv) { + if (pv == nullptr) { return nullptr; } const JSCStringValue* string = static_cast(pv); @@ -914,7 +914,7 @@ JSClassRef getNativeStateClass() { } // namespace JSValueRef JSCRuntime::getNativeStateSymbol() { - if (!nativeStateSymbol_) { + if (nativeStateSymbol_ == nullptr) { JSStringRef symbolName = JSStringCreateWithUTF8CString("__internal_nativeState"); JSValueRef symbol = JSValueMakeSymbol(ctx_, symbolName); @@ -1182,7 +1182,7 @@ jsi::Function JSCRuntime::createFunctionFromHostFunction( kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete, &exc); - if (exc) { + if (exc != nullptr) { // Silently fail to set length exc = nullptr; } @@ -1198,7 +1198,7 @@ jsi::Function JSCRuntime::createFunctionFromHostFunction( kJSPropertyAttributeDontDelete, &exc); JSStringRelease(name); - if (exc) { + if (exc != nullptr) { // Silently fail to set name exc = nullptr; } @@ -1211,7 +1211,7 @@ jsi::Function JSCRuntime::createFunctionFromHostFunction( abort(); } JSObjectRef funcCtor = JSValueToObject(ctx, value, &exc); - if (!funcCtor) { + if (funcCtor == nullptr) { // We can't do anything if Function is not an object return; } @@ -1439,7 +1439,7 @@ JSStringRef getEmptyString() { jsi::Runtime::PointerValue* JSCRuntime::makeStringValue( JSStringRef stringRef) const { - if (!stringRef) { + if (stringRef == nullptr) { stringRef = getEmptyString(); } #ifndef NDEBUG @@ -1463,7 +1463,7 @@ jsi::PropNameID JSCRuntime::createPropNameID(JSStringRef str) { jsi::Runtime::PointerValue* JSCRuntime::makeObjectValue( JSObjectRef objectRef) const { - if (!objectRef) { + if (objectRef == nullptr) { objectRef = JSObjectMake(ctx_, nullptr, nullptr); } #ifndef NDEBUG diff --git a/packages/react-native/ReactCommon/jsinspector-modern/tests/InspectorPackagerConnectionTest.cpp b/packages/react-native/ReactCommon/jsinspector-modern/tests/InspectorPackagerConnectionTest.cpp index 5b237b73ee9..f61eca78251 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/tests/InspectorPackagerConnectionTest.cpp +++ b/packages/react-native/ReactCommon/jsinspector-modern/tests/InspectorPackagerConnectionTest.cpp @@ -59,7 +59,7 @@ class InspectorPackagerConnectionTestBase : public testing::Test { auto pages = getInspectorInstance().getPages(); int liveConnectionCount = 0; for (size_t i = 0; i != localConnections_.objectsVended(); ++i) { - if (localConnections_[i]) { + if (localConnections_[i] != nullptr) { liveConnectionCount++; // localConnections_[i] is a strict mock and will complain when we // removePage if the call is unexpected. @@ -69,7 +69,7 @@ class InspectorPackagerConnectionTestBase : public testing::Test { for (auto& page : pages) { getInspectorInstance().removePage(page.id); } - if (!pages.empty() && liveConnectionCount) { + if (!pages.empty() && (liveConnectionCount != 0)) { if (!::testing::Test::HasFailure()) { FAIL() << "Test case ended with " << liveConnectionCount diff --git a/packages/react-native/ReactCommon/jsinspector-modern/tests/JsiIntegrationTest.h b/packages/react-native/ReactCommon/jsinspector-modern/tests/JsiIntegrationTest.h index c8cd9249418..9c53181f50e 100644 --- a/packages/react-native/ReactCommon/jsinspector-modern/tests/JsiIntegrationTest.h +++ b/packages/react-native/ReactCommon/jsinspector-modern/tests/JsiIntegrationTest.h @@ -65,12 +65,12 @@ class JsiIntegrationPortableTestBase : public ::testing::Test, ~JsiIntegrationPortableTestBase() override { toPage_.reset(); - if (runtimeTarget_) { + if (runtimeTarget_ != nullptr) { EXPECT_TRUE(instance_); instance_->unregisterRuntime(*runtimeTarget_); runtimeTarget_ = nullptr; } - if (instance_) { + if (instance_ != nullptr) { page_->unregisterInstance(*instance_); instance_ = nullptr; } @@ -108,12 +108,12 @@ class JsiIntegrationPortableTestBase : public ::testing::Test, } void reload() { - if (runtimeTarget_) { + if (runtimeTarget_ != nullptr) { ASSERT_TRUE(instance_); instance_->unregisterRuntime(*runtimeTarget_); runtimeTarget_ = nullptr; } - if (instance_) { + if (instance_ != nullptr) { page_->unregisterInstance(*instance_); instance_ = nullptr; } diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp b/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp index 1b1c6f7f7e7..5c9b464a8c3 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/android/ReactCommon/JavaTurboModule.cpp @@ -395,7 +395,8 @@ JNIArgs convertJSIArgsToJNIArgs( "boolean", argIndex, methodName, arg, &rt); } jarg->l = makeGlobalIfNecessary( - jni::JBoolean::valueOf(arg->getBool()).release()); + jni::JBoolean::valueOf(static_cast(arg->getBool())) + .release()); } else if (type == "Ljava/lang/String;") { if (!arg->isString()) { throw JavaTurboModuleArgumentConversionException(